Centering table data under right-aligned tabularx header












1















I'm trying to align the following table so that the "21" is centered under its header.



begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|cll>{raggedleftarraybackslash}X|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
textbf{Occurrences} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}


enter image description here



I can use centering instead of raggedleft for the last column to center the numbers under the header but then the header ends up too much to the left, I want the header to be like in the above picture.



enter image description here



Is there anyway I can get the combination of these two? The header aligned to the right like in the first picture but the number centered under the header like in the second picture.










share|improve this question























  • Welcome to TeX SX! Have you any reason for a tabularx which flows into the margins?

    – Bernard
    Mar 18 at 10:21











  • @Bernard The reason i'm using tabularx is to get the same width as my widest table

    – antmo
    Mar 18 at 10:27
















1















I'm trying to align the following table so that the "21" is centered under its header.



begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|cll>{raggedleftarraybackslash}X|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
textbf{Occurrences} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}


enter image description here



I can use centering instead of raggedleft for the last column to center the numbers under the header but then the header ends up too much to the left, I want the header to be like in the above picture.



enter image description here



Is there anyway I can get the combination of these two? The header aligned to the right like in the first picture but the number centered under the header like in the second picture.










share|improve this question























  • Welcome to TeX SX! Have you any reason for a tabularx which flows into the margins?

    – Bernard
    Mar 18 at 10:21











  • @Bernard The reason i'm using tabularx is to get the same width as my widest table

    – antmo
    Mar 18 at 10:27














1












1








1








I'm trying to align the following table so that the "21" is centered under its header.



begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|cll>{raggedleftarraybackslash}X|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
textbf{Occurrences} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}


enter image description here



I can use centering instead of raggedleft for the last column to center the numbers under the header but then the header ends up too much to the left, I want the header to be like in the above picture.



enter image description here



Is there anyway I can get the combination of these two? The header aligned to the right like in the first picture but the number centered under the header like in the second picture.










share|improve this question














I'm trying to align the following table so that the "21" is centered under its header.



begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|cll>{raggedleftarraybackslash}X|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
textbf{Occurrences} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}


enter image description here



I can use centering instead of raggedleft for the last column to center the numbers under the header but then the header ends up too much to the left, I want the header to be like in the above picture.



enter image description here



Is there anyway I can get the combination of these two? The header aligned to the right like in the first picture but the number centered under the header like in the second picture.







tables tabularx alignment






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 18 at 10:06









antmoantmo

82




82













  • Welcome to TeX SX! Have you any reason for a tabularx which flows into the margins?

    – Bernard
    Mar 18 at 10:21











  • @Bernard The reason i'm using tabularx is to get the same width as my widest table

    – antmo
    Mar 18 at 10:27



















  • Welcome to TeX SX! Have you any reason for a tabularx which flows into the margins?

    – Bernard
    Mar 18 at 10:21











  • @Bernard The reason i'm using tabularx is to get the same width as my widest table

    – antmo
    Mar 18 at 10:27

















Welcome to TeX SX! Have you any reason for a tabularx which flows into the margins?

– Bernard
Mar 18 at 10:21





Welcome to TeX SX! Have you any reason for a tabularx which flows into the margins?

– Bernard
Mar 18 at 10:21













@Bernard The reason i'm using tabularx is to get the same width as my widest table

– antmo
Mar 18 at 10:27





@Bernard The reason i'm using tabularx is to get the same width as my widest table

– antmo
Mar 18 at 10:27










1 Answer
1






active

oldest

votes


















2














I would use the X type colum for the 3rd instead of the 4th cell: begin{tabularx}{1.09textwidth}{|clXc|}. With makecell[r]{textbf{Occurrences}} you can then right align the header:



documentclass{article}

usepackage{tabularx}
usepackage{makecell}

begin{document}
begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|clXc|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
makecell[r]{textbf{Occurrences}} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}
end{document}





share|improve this answer



















  • 2





    Maybe using thead for all column heads would simplify the code?

    – Bernard
    Mar 18 at 10:19






  • 1





    Thank you, that was an easy solution that gives the right look!

    – antmo
    Mar 18 at 10:21











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f480053%2fcentering-table-data-under-right-aligned-tabularx-header%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














I would use the X type colum for the 3rd instead of the 4th cell: begin{tabularx}{1.09textwidth}{|clXc|}. With makecell[r]{textbf{Occurrences}} you can then right align the header:



documentclass{article}

usepackage{tabularx}
usepackage{makecell}

begin{document}
begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|clXc|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
makecell[r]{textbf{Occurrences}} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}
end{document}





share|improve this answer



















  • 2





    Maybe using thead for all column heads would simplify the code?

    – Bernard
    Mar 18 at 10:19






  • 1





    Thank you, that was an easy solution that gives the right look!

    – antmo
    Mar 18 at 10:21
















2














I would use the X type colum for the 3rd instead of the 4th cell: begin{tabularx}{1.09textwidth}{|clXc|}. With makecell[r]{textbf{Occurrences}} you can then right align the header:



documentclass{article}

usepackage{tabularx}
usepackage{makecell}

begin{document}
begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|clXc|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
makecell[r]{textbf{Occurrences}} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}
end{document}





share|improve this answer



















  • 2





    Maybe using thead for all column heads would simplify the code?

    – Bernard
    Mar 18 at 10:19






  • 1





    Thank you, that was an easy solution that gives the right look!

    – antmo
    Mar 18 at 10:21














2












2








2







I would use the X type colum for the 3rd instead of the 4th cell: begin{tabularx}{1.09textwidth}{|clXc|}. With makecell[r]{textbf{Occurrences}} you can then right align the header:



documentclass{article}

usepackage{tabularx}
usepackage{makecell}

begin{document}
begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|clXc|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
makecell[r]{textbf{Occurrences}} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}
end{document}





share|improve this answer













I would use the X type colum for the 3rd instead of the 4th cell: begin{tabularx}{1.09textwidth}{|clXc|}. With makecell[r]{textbf{Occurrences}} you can then right align the header:



documentclass{article}

usepackage{tabularx}
usepackage{makecell}

begin{document}
begin{table}[h]
centering
begin{tabularx}{1.09textwidth}{|clXc|}
hline
textbf{ID} & textbf{Severity} & textbf{Vulnerability} &
makecell[r]{textbf{Occurrences}} \
hline
111111 & Lorem & Lorem ipsum dolor sit amet & 21 \
hline
end{tabularx}
caption{example}
label{table:example}
end{table}
end{document}






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 18 at 10:13









leandriisleandriis

10.8k1732




10.8k1732








  • 2





    Maybe using thead for all column heads would simplify the code?

    – Bernard
    Mar 18 at 10:19






  • 1





    Thank you, that was an easy solution that gives the right look!

    – antmo
    Mar 18 at 10:21














  • 2





    Maybe using thead for all column heads would simplify the code?

    – Bernard
    Mar 18 at 10:19






  • 1





    Thank you, that was an easy solution that gives the right look!

    – antmo
    Mar 18 at 10:21








2




2





Maybe using thead for all column heads would simplify the code?

– Bernard
Mar 18 at 10:19





Maybe using thead for all column heads would simplify the code?

– Bernard
Mar 18 at 10:19




1




1





Thank you, that was an easy solution that gives the right look!

– antmo
Mar 18 at 10:21





Thank you, that was an easy solution that gives the right look!

– antmo
Mar 18 at 10:21


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f480053%2fcentering-table-data-under-right-aligned-tabularx-header%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents