Both horizontal and vertical centering in tabularx?












1















How to set a width of columns to be centered in vertical direction? Or in vertical and horizontal direction and the cells bellow as well?
Thank you



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}
setlengthtextwidth{145mm}
setlengthtextheight{247mm}
setlengthoddsidemargin{15mm}
setlengthevensidemargin{15mm}
setlengthtopmargin{0mm}
setlengthheadsep{0mm}
setlengthheadheight{0mm}
letopenright=clearpage
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}X
>{hsize=0.25hsize}X
>{hsize=0.25hsize}X
>{hsize=0.3hsize}X}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& makecell{Odchylka určení \ průměrné chyby}& makecell{Počet středovaných \ bodů}\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


enter image description here










share|improve this question




















  • 1





    Do you like the tables :-)? Why do not use the geometry package to set the page?

    – Sebastiano
    Jan 2 at 20:41
















1















How to set a width of columns to be centered in vertical direction? Or in vertical and horizontal direction and the cells bellow as well?
Thank you



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}
setlengthtextwidth{145mm}
setlengthtextheight{247mm}
setlengthoddsidemargin{15mm}
setlengthevensidemargin{15mm}
setlengthtopmargin{0mm}
setlengthheadsep{0mm}
setlengthheadheight{0mm}
letopenright=clearpage
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}X
>{hsize=0.25hsize}X
>{hsize=0.25hsize}X
>{hsize=0.3hsize}X}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& makecell{Odchylka určení \ průměrné chyby}& makecell{Počet středovaných \ bodů}\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


enter image description here










share|improve this question




















  • 1





    Do you like the tables :-)? Why do not use the geometry package to set the page?

    – Sebastiano
    Jan 2 at 20:41














1












1








1








How to set a width of columns to be centered in vertical direction? Or in vertical and horizontal direction and the cells bellow as well?
Thank you



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}
setlengthtextwidth{145mm}
setlengthtextheight{247mm}
setlengthoddsidemargin{15mm}
setlengthevensidemargin{15mm}
setlengthtopmargin{0mm}
setlengthheadsep{0mm}
setlengthheadheight{0mm}
letopenright=clearpage
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}X
>{hsize=0.25hsize}X
>{hsize=0.25hsize}X
>{hsize=0.3hsize}X}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& makecell{Odchylka určení \ průměrné chyby}& makecell{Počet středovaných \ bodů}\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


enter image description here










share|improve this question
















How to set a width of columns to be centered in vertical direction? Or in vertical and horizontal direction and the cells bellow as well?
Thank you



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}
setlengthtextwidth{145mm}
setlengthtextheight{247mm}
setlengthoddsidemargin{15mm}
setlengthevensidemargin{15mm}
setlengthtopmargin{0mm}
setlengthheadsep{0mm}
setlengthheadheight{0mm}
letopenright=clearpage
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}X
>{hsize=0.25hsize}X
>{hsize=0.25hsize}X
>{hsize=0.3hsize}X}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& makecell{Odchylka určení \ průměrné chyby}& makecell{Počet středovaných \ bodů}\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


enter image description here







tables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 20:58









AboAmmar

33.4k22882




33.4k22882










asked Jan 2 at 20:37









ElisabethElisabeth

4926




4926








  • 1





    Do you like the tables :-)? Why do not use the geometry package to set the page?

    – Sebastiano
    Jan 2 at 20:41














  • 1





    Do you like the tables :-)? Why do not use the geometry package to set the page?

    – Sebastiano
    Jan 2 at 20:41








1




1





Do you like the tables :-)? Why do not use the geometry package to set the page?

– Sebastiano
Jan 2 at 20:41





Do you like the tables :-)? Why do not use the geometry package to set the page?

– Sebastiano
Jan 2 at 20:41










2 Answers
2






active

oldest

votes


















5














Combining renewcommandtabularxcolumn[1]{m{#1}} (from Vertical centering of all columns in tabularx environment) and newcolumntype{C}{>{centeringarraybackslash}X} (from Centering in tabularx and X columns) you can achieve the following:



enter image description here



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}


renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& Odchylka určení průměrné chyby& Počet středovaných bodů\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


Please keep in mind that I have removed the makecell cmmands as they distorted the vertical alignment. If you need to place the linebreaks manually, you can either use makecell[cc]{<text>} in every column header (as suggested by Paul Stanley in the comments) or replace newcolumntype{C}{>{centeringarraybackslash}X} by newcolumntype{C}{>{centeringletnewline\arraybackslash}X} and use newline where you want the linebreak to appear.






share|improve this answer


























  • I ment centering like in the solution. Thank you. And please is the third column vertical centred? I mean that third and forth columns are lower

    – Elisabeth
    Jan 2 at 20:56








  • 1





    @Elisabeth: makecell seems to have interfered with the vertical centering of the m type columns. I have therefor removed it.

    – leandriis
    Jan 2 at 21:01











  • @leandriis Now you have eliminated the makecells, which corrects the vertical spacing, but alters the substance. Probably better to put all the headings in makecells or add an optional vertical positioning argument to them?

    – Paul Stanley
    Jan 2 at 21:04











  • Thank you very much. It is exactly what I expected.

    – Elisabeth
    Jan 2 at 21:05











  • @PaulStanley: What do you mean by 'alter the substance'?

    – leandriis
    Jan 2 at 21:08



















3














Improving a bit upon the nice solution of @leandriis, I would also remove all manual rule width manipulations and just use booktabs macros, they take care of widths and separation nicely. No need for makecell as also stated by leandriis.



If you want to break lines at certain points and used makecell to do that, then you can still use newline for that.



documentclass[12pt,a4paper]{report}
usepackage{booktabs, tabularx}

renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}
toprule%
Název souboru & Průměrná hodnota chyby & Odchylka určení průměrné chyby & Počet středovaných bodů \
midrule
B & A & C & D \
bottomrule
end{tabularx}
end{table}

end{document}



enter image description here







share|improve this answer


























  • Did you test the part about newline with your above example? If I add this to your code, the first line is not horizontally centered: i.stack.imgur.com/SIJx3.png You can bypass this using newcolumntype{C}{>{centeringletnewline\arraybackslash}X} instead.

    – leandriis
    Jan 2 at 21:22








  • 1





    par can be used instead.

    – AboAmmar
    Jan 2 at 22:04











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%2f468318%2fboth-horizontal-and-vertical-centering-in-tabularx%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Combining renewcommandtabularxcolumn[1]{m{#1}} (from Vertical centering of all columns in tabularx environment) and newcolumntype{C}{>{centeringarraybackslash}X} (from Centering in tabularx and X columns) you can achieve the following:



enter image description here



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}


renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& Odchylka určení průměrné chyby& Počet středovaných bodů\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


Please keep in mind that I have removed the makecell cmmands as they distorted the vertical alignment. If you need to place the linebreaks manually, you can either use makecell[cc]{<text>} in every column header (as suggested by Paul Stanley in the comments) or replace newcolumntype{C}{>{centeringarraybackslash}X} by newcolumntype{C}{>{centeringletnewline\arraybackslash}X} and use newline where you want the linebreak to appear.






share|improve this answer


























  • I ment centering like in the solution. Thank you. And please is the third column vertical centred? I mean that third and forth columns are lower

    – Elisabeth
    Jan 2 at 20:56








  • 1





    @Elisabeth: makecell seems to have interfered with the vertical centering of the m type columns. I have therefor removed it.

    – leandriis
    Jan 2 at 21:01











  • @leandriis Now you have eliminated the makecells, which corrects the vertical spacing, but alters the substance. Probably better to put all the headings in makecells or add an optional vertical positioning argument to them?

    – Paul Stanley
    Jan 2 at 21:04











  • Thank you very much. It is exactly what I expected.

    – Elisabeth
    Jan 2 at 21:05











  • @PaulStanley: What do you mean by 'alter the substance'?

    – leandriis
    Jan 2 at 21:08
















5














Combining renewcommandtabularxcolumn[1]{m{#1}} (from Vertical centering of all columns in tabularx environment) and newcolumntype{C}{>{centeringarraybackslash}X} (from Centering in tabularx and X columns) you can achieve the following:



enter image description here



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}


renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& Odchylka určení průměrné chyby& Počet středovaných bodů\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


Please keep in mind that I have removed the makecell cmmands as they distorted the vertical alignment. If you need to place the linebreaks manually, you can either use makecell[cc]{<text>} in every column header (as suggested by Paul Stanley in the comments) or replace newcolumntype{C}{>{centeringarraybackslash}X} by newcolumntype{C}{>{centeringletnewline\arraybackslash}X} and use newline where you want the linebreak to appear.






share|improve this answer


























  • I ment centering like in the solution. Thank you. And please is the third column vertical centred? I mean that third and forth columns are lower

    – Elisabeth
    Jan 2 at 20:56








  • 1





    @Elisabeth: makecell seems to have interfered with the vertical centering of the m type columns. I have therefor removed it.

    – leandriis
    Jan 2 at 21:01











  • @leandriis Now you have eliminated the makecells, which corrects the vertical spacing, but alters the substance. Probably better to put all the headings in makecells or add an optional vertical positioning argument to them?

    – Paul Stanley
    Jan 2 at 21:04











  • Thank you very much. It is exactly what I expected.

    – Elisabeth
    Jan 2 at 21:05











  • @PaulStanley: What do you mean by 'alter the substance'?

    – leandriis
    Jan 2 at 21:08














5












5








5







Combining renewcommandtabularxcolumn[1]{m{#1}} (from Vertical centering of all columns in tabularx environment) and newcolumntype{C}{>{centeringarraybackslash}X} (from Centering in tabularx and X columns) you can achieve the following:



enter image description here



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}


renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& Odchylka určení průměrné chyby& Počet středovaných bodů\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


Please keep in mind that I have removed the makecell cmmands as they distorted the vertical alignment. If you need to place the linebreaks manually, you can either use makecell[cc]{<text>} in every column header (as suggested by Paul Stanley in the comments) or replace newcolumntype{C}{>{centeringarraybackslash}X} by newcolumntype{C}{>{centeringletnewline\arraybackslash}X} and use newline where you want the linebreak to appear.






share|improve this answer















Combining renewcommandtabularxcolumn[1]{m{#1}} (from Vertical centering of all columns in tabularx environment) and newcolumntype{C}{>{centeringarraybackslash}X} (from Centering in tabularx and X columns) you can achieve the following:



enter image description here



documentclass[12pt,a4paper]{report}
usepackage{booktabs, makecell, tabularx}


renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}

Xhline{1.2pt}noalign{vskip 0.4ex}Xhline{1.2pt}%
Název souboru& Průměrná hodnota chyby& Odchylka určení průměrné chyby& Počet středovaných bodů\
Xhline{1.2pt}noalign{vskip 0.4ex}
B & A& C& D\

Xhline{1.2pt}
end{tabularx}
end{table}

end{document}


Please keep in mind that I have removed the makecell cmmands as they distorted the vertical alignment. If you need to place the linebreaks manually, you can either use makecell[cc]{<text>} in every column header (as suggested by Paul Stanley in the comments) or replace newcolumntype{C}{>{centeringarraybackslash}X} by newcolumntype{C}{>{centeringletnewline\arraybackslash}X} and use newline where you want the linebreak to appear.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 21:27

























answered Jan 2 at 20:43









leandriisleandriis

8,4921529




8,4921529













  • I ment centering like in the solution. Thank you. And please is the third column vertical centred? I mean that third and forth columns are lower

    – Elisabeth
    Jan 2 at 20:56








  • 1





    @Elisabeth: makecell seems to have interfered with the vertical centering of the m type columns. I have therefor removed it.

    – leandriis
    Jan 2 at 21:01











  • @leandriis Now you have eliminated the makecells, which corrects the vertical spacing, but alters the substance. Probably better to put all the headings in makecells or add an optional vertical positioning argument to them?

    – Paul Stanley
    Jan 2 at 21:04











  • Thank you very much. It is exactly what I expected.

    – Elisabeth
    Jan 2 at 21:05











  • @PaulStanley: What do you mean by 'alter the substance'?

    – leandriis
    Jan 2 at 21:08



















  • I ment centering like in the solution. Thank you. And please is the third column vertical centred? I mean that third and forth columns are lower

    – Elisabeth
    Jan 2 at 20:56








  • 1





    @Elisabeth: makecell seems to have interfered with the vertical centering of the m type columns. I have therefor removed it.

    – leandriis
    Jan 2 at 21:01











  • @leandriis Now you have eliminated the makecells, which corrects the vertical spacing, but alters the substance. Probably better to put all the headings in makecells or add an optional vertical positioning argument to them?

    – Paul Stanley
    Jan 2 at 21:04











  • Thank you very much. It is exactly what I expected.

    – Elisabeth
    Jan 2 at 21:05











  • @PaulStanley: What do you mean by 'alter the substance'?

    – leandriis
    Jan 2 at 21:08

















I ment centering like in the solution. Thank you. And please is the third column vertical centred? I mean that third and forth columns are lower

– Elisabeth
Jan 2 at 20:56







I ment centering like in the solution. Thank you. And please is the third column vertical centred? I mean that third and forth columns are lower

– Elisabeth
Jan 2 at 20:56






1




1





@Elisabeth: makecell seems to have interfered with the vertical centering of the m type columns. I have therefor removed it.

– leandriis
Jan 2 at 21:01





@Elisabeth: makecell seems to have interfered with the vertical centering of the m type columns. I have therefor removed it.

– leandriis
Jan 2 at 21:01













@leandriis Now you have eliminated the makecells, which corrects the vertical spacing, but alters the substance. Probably better to put all the headings in makecells or add an optional vertical positioning argument to them?

– Paul Stanley
Jan 2 at 21:04





@leandriis Now you have eliminated the makecells, which corrects the vertical spacing, but alters the substance. Probably better to put all the headings in makecells or add an optional vertical positioning argument to them?

– Paul Stanley
Jan 2 at 21:04













Thank you very much. It is exactly what I expected.

– Elisabeth
Jan 2 at 21:05





Thank you very much. It is exactly what I expected.

– Elisabeth
Jan 2 at 21:05













@PaulStanley: What do you mean by 'alter the substance'?

– leandriis
Jan 2 at 21:08





@PaulStanley: What do you mean by 'alter the substance'?

– leandriis
Jan 2 at 21:08











3














Improving a bit upon the nice solution of @leandriis, I would also remove all manual rule width manipulations and just use booktabs macros, they take care of widths and separation nicely. No need for makecell as also stated by leandriis.



If you want to break lines at certain points and used makecell to do that, then you can still use newline for that.



documentclass[12pt,a4paper]{report}
usepackage{booktabs, tabularx}

renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}
toprule%
Název souboru & Průměrná hodnota chyby & Odchylka určení průměrné chyby & Počet středovaných bodů \
midrule
B & A & C & D \
bottomrule
end{tabularx}
end{table}

end{document}



enter image description here







share|improve this answer


























  • Did you test the part about newline with your above example? If I add this to your code, the first line is not horizontally centered: i.stack.imgur.com/SIJx3.png You can bypass this using newcolumntype{C}{>{centeringletnewline\arraybackslash}X} instead.

    – leandriis
    Jan 2 at 21:22








  • 1





    par can be used instead.

    – AboAmmar
    Jan 2 at 22:04
















3














Improving a bit upon the nice solution of @leandriis, I would also remove all manual rule width manipulations and just use booktabs macros, they take care of widths and separation nicely. No need for makecell as also stated by leandriis.



If you want to break lines at certain points and used makecell to do that, then you can still use newline for that.



documentclass[12pt,a4paper]{report}
usepackage{booktabs, tabularx}

renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}
toprule%
Název souboru & Průměrná hodnota chyby & Odchylka určení průměrné chyby & Počet středovaných bodů \
midrule
B & A & C & D \
bottomrule
end{tabularx}
end{table}

end{document}



enter image description here







share|improve this answer


























  • Did you test the part about newline with your above example? If I add this to your code, the first line is not horizontally centered: i.stack.imgur.com/SIJx3.png You can bypass this using newcolumntype{C}{>{centeringletnewline\arraybackslash}X} instead.

    – leandriis
    Jan 2 at 21:22








  • 1





    par can be used instead.

    – AboAmmar
    Jan 2 at 22:04














3












3








3







Improving a bit upon the nice solution of @leandriis, I would also remove all manual rule width manipulations and just use booktabs macros, they take care of widths and separation nicely. No need for makecell as also stated by leandriis.



If you want to break lines at certain points and used makecell to do that, then you can still use newline for that.



documentclass[12pt,a4paper]{report}
usepackage{booktabs, tabularx}

renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}
toprule%
Název souboru & Průměrná hodnota chyby & Odchylka určení průměrné chyby & Počet středovaných bodů \
midrule
B & A & C & D \
bottomrule
end{tabularx}
end{table}

end{document}



enter image description here







share|improve this answer















Improving a bit upon the nice solution of @leandriis, I would also remove all manual rule width manipulations and just use booktabs macros, they take care of widths and separation nicely. No need for makecell as also stated by leandriis.



If you want to break lines at certain points and used makecell to do that, then you can still use newline for that.



documentclass[12pt,a4paper]{report}
usepackage{booktabs, tabularx}

renewcommandtabularxcolumn[1]{m{#1}}
newcolumntype{C}{>{centeringarraybackslash}X}
begin{document}
begin{table}
small
renewcommand{arraystretch}{1.2}
begin{tabularx}{textwidth}{>{hsize=0.2hsize}C
>{hsize=0.25hsize}C
>{hsize=0.25hsize}C
>{hsize=0.3hsize}C}
toprule%
Název souboru & Průměrná hodnota chyby & Odchylka určení průměrné chyby & Počet středovaných bodů \
midrule
B & A & C & D \
bottomrule
end{tabularx}
end{table}

end{document}



enter image description here








share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 21:17

























answered Jan 2 at 21:11









AboAmmarAboAmmar

33.4k22882




33.4k22882













  • Did you test the part about newline with your above example? If I add this to your code, the first line is not horizontally centered: i.stack.imgur.com/SIJx3.png You can bypass this using newcolumntype{C}{>{centeringletnewline\arraybackslash}X} instead.

    – leandriis
    Jan 2 at 21:22








  • 1





    par can be used instead.

    – AboAmmar
    Jan 2 at 22:04



















  • Did you test the part about newline with your above example? If I add this to your code, the first line is not horizontally centered: i.stack.imgur.com/SIJx3.png You can bypass this using newcolumntype{C}{>{centeringletnewline\arraybackslash}X} instead.

    – leandriis
    Jan 2 at 21:22








  • 1





    par can be used instead.

    – AboAmmar
    Jan 2 at 22:04

















Did you test the part about newline with your above example? If I add this to your code, the first line is not horizontally centered: i.stack.imgur.com/SIJx3.png You can bypass this using newcolumntype{C}{>{centeringletnewline\arraybackslash}X} instead.

– leandriis
Jan 2 at 21:22







Did you test the part about newline with your above example? If I add this to your code, the first line is not horizontally centered: i.stack.imgur.com/SIJx3.png You can bypass this using newcolumntype{C}{>{centeringletnewline\arraybackslash}X} instead.

– leandriis
Jan 2 at 21:22






1




1





par can be used instead.

– AboAmmar
Jan 2 at 22:04





par can be used instead.

– AboAmmar
Jan 2 at 22:04


















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%2f468318%2fboth-horizontal-and-vertical-centering-in-tabularx%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

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

WPF add header to Image with URL pettitions [duplicate]