Trouble with formatting a tabularx environment












3















I've been trying to format a table without success. I've followed several suggestions that I found in other answers but never manage to fully adapt it.



This is one of the examples I tried:



documentclass{article}
usepackage{booktabs, tabularx}
begin{document}
begin{center}
begin{tabularx}{linewidth}{cr*{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}
end{document}


A things to be fixed but I haven't been able to:




  • The names in the header should be centered vertically and I'd prefer the units in a different line.

  • There seems to be an empty column at the end?

  • bonus: How can I add a footnote to make a comment on one value? tried adding footnotesize{} but the table and the footnote end up in different places.


Overall I just want a decent and simple graph but can't see h










share|improve this question

























  • The "empty column at the end" phenomenon is not really an empty column. Instead, it's an artifact of the failure to employ one or more columns of type X.

    – Mico
    Feb 14 at 17:40


















3















I've been trying to format a table without success. I've followed several suggestions that I found in other answers but never manage to fully adapt it.



This is one of the examples I tried:



documentclass{article}
usepackage{booktabs, tabularx}
begin{document}
begin{center}
begin{tabularx}{linewidth}{cr*{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}
end{document}


A things to be fixed but I haven't been able to:




  • The names in the header should be centered vertically and I'd prefer the units in a different line.

  • There seems to be an empty column at the end?

  • bonus: How can I add a footnote to make a comment on one value? tried adding footnotesize{} but the table and the footnote end up in different places.


Overall I just want a decent and simple graph but can't see h










share|improve this question

























  • The "empty column at the end" phenomenon is not really an empty column. Instead, it's an artifact of the failure to employ one or more columns of type X.

    – Mico
    Feb 14 at 17:40
















3












3








3








I've been trying to format a table without success. I've followed several suggestions that I found in other answers but never manage to fully adapt it.



This is one of the examples I tried:



documentclass{article}
usepackage{booktabs, tabularx}
begin{document}
begin{center}
begin{tabularx}{linewidth}{cr*{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}
end{document}


A things to be fixed but I haven't been able to:




  • The names in the header should be centered vertically and I'd prefer the units in a different line.

  • There seems to be an empty column at the end?

  • bonus: How can I add a footnote to make a comment on one value? tried adding footnotesize{} but the table and the footnote end up in different places.


Overall I just want a decent and simple graph but can't see h










share|improve this question
















I've been trying to format a table without success. I've followed several suggestions that I found in other answers but never manage to fully adapt it.



This is one of the examples I tried:



documentclass{article}
usepackage{booktabs, tabularx}
begin{document}
begin{center}
begin{tabularx}{linewidth}{cr*{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}
end{document}


A things to be fixed but I haven't been able to:




  • The names in the header should be centered vertically and I'd prefer the units in a different line.

  • There seems to be an empty column at the end?

  • bonus: How can I add a footnote to make a comment on one value? tried adding footnotesize{} but the table and the footnote end up in different places.


Overall I just want a decent and simple graph but can't see h







tables tabularx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 14 at 17:36









Mico

279k31381770




279k31381770










asked Feb 14 at 16:59









egil137egil137

425




425













  • The "empty column at the end" phenomenon is not really an empty column. Instead, it's an artifact of the failure to employ one or more columns of type X.

    – Mico
    Feb 14 at 17:40





















  • The "empty column at the end" phenomenon is not really an empty column. Instead, it's an artifact of the failure to employ one or more columns of type X.

    – Mico
    Feb 14 at 17:40



















The "empty column at the end" phenomenon is not really an empty column. Instead, it's an artifact of the failure to employ one or more columns of type X.

– Mico
Feb 14 at 17:40







The "empty column at the end" phenomenon is not really an empty column. Instead, it's an artifact of the failure to employ one or more columns of type X.

– Mico
Feb 14 at 17:40












2 Answers
2






active

oldest

votes


















2














You don't need tabularx, which is the wrong tool for a numeric table. Use tabular* and siunitx facilities.



I provide two realizations, the second one without extending the table up to the margins, which seems better.



documentclass{article}
usepackage{booktabs,siunitx}

sisetup{separate-uncertainty}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

begin{table}[htp]
centering

caption{Something that describes the table}label{whatever2}

begin{tabular}{
@{}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
@{}
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular}

end{table}

end{document}


enter image description here



You can center the header in the first column by using multicolumn{1}{c}{Probe} (or multicolumn{1}{@{}c}{Probe} for the second realization, where we remove the padding on the left of the first column).



I added also a trick for pulling the units nearer the header.



documentclass{article}
usepackage{amsmath,booktabs,siunitx}

sisetup{separate-uncertainty}

newcommand{tabhead}[1]{%
smash[b]{%
begin{tabular}[t]{@{}c@{}}#1end{tabular}%
}%
}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
multicolumn{1}{c}{Probe} &
{tabhead{MW \ (si{g/mol})}} &
{tabhead{R \ (si{nm})}} &
multicolumn{4}{c}{V (si{mL/g})} &
{tabhead{K \ (--)}} \
cmidrule{4-7}
&&& {1} & {2} & {3} & {avg.} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

end{document}


enter image description here






share|improve this answer





















  • 1





    I guess there might still be a rationale for using a tabularx rather than a tabular* environment: If the entries in the first column are a bit more descriptive, and a lot longer, than Label 1, Label 2, etc., it would be useful to assign the X column type to the first column and thus enable automatic line wrapping. At least, I would fervently hope that the real table's headers are a bit more informative than "Label 1", "Label 2", etc are...

    – Mico
    Feb 14 at 21:53











  • Thank you! didn't know the difference between tabular and tabularx. Any ideas how to center probe in the middle and make the other labels closer to the units? I'd like to reduce the white space between them.

    – egil137
    Feb 15 at 9:28











  • @egil137 I wouldn't center the header, but it's a stylistic choice. I added the other trick you asked for.

    – egreg
    Feb 15 at 9:37













  • Looks great! I have a new problem though :/ I'm working with a template and noticed that this line is preventing the correct spacing so it's preventing tabhead to work: renewcommand{baselinestretch}{1.5}. I would be afraid of removing this line and affecting some other formatting, or would this only affect tables?

    – egil137
    Feb 15 at 10:06











  • @egil137 Add renewcommand{arraystretch}{0.66667} in your document preamble, which will remove the stretching in tables.

    – egreg
    Feb 15 at 10:09



















2














Some suggestions:





  • When using the tabularx environment, make sure to use at least one column of type X. For the table at hand, it seems OK to change the type of the first column from l to X. I'm assuming (hoping?!) that the "real" column labels will be more descriptive, and thus possibly also longer, than "Label 1", "Label 2", and "Label 3". If that's the case, it's useful to use the X column type for the first column as it allows automatic linebreaking. (The l column type does not.) In contrast, there would appear to be no scope for allowing line breaks in any of the other columns.



    The appearance of what looks like an empty column at the right-hand edge of your code is caused directly by the failure to use one or more columns of type X.



  • As you've discovered, using newline in a cell doesn't work. In the answer below, I propose a handy macro to typeset a header cell and associated units in a stacked format.


  • Optional: Consider using the siunitx package to (a) typeset scientific units properly (via he package's si macro) and (b) align the numbers in columns 2 and 3 on their (explicit or implicit) decimal markers (via the package's S column type).



enter image description here



documentclass{article}
usepackage{booktabs, tabularx, siunitx, xcolor}
sisetup{per-mode=symbol,group-digits=false}

%% handy utility macro:
newcommandsmalltab[1]{%
smash{begin{tabular}[t]{@{}c@{}} #1 end{tabular}}}

begin{document}

noindent
textcolor{red}{Before}

begin{center}
begin{tabularx}{linewidth}{@{} l r *{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

bigskipnoindent
textcolor{red}{After}

begin{center}
begin{tabularx}{linewidth}{@{} X
S[table-format=6.0] S[table-format=2.2] *{5}{c} @{}}
toprule
Probe & smalltab{MW\(si{grampermole})}
& smalltab{R\(si{nanometer})}
& multicolumn{4}{c}{V (si{milliliterpergram})}
& smalltab{K\(--)} \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32,${pm}$,0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

end{document}





share|improve this answer


























  • Regarding your "bonus" question: I suggest you look into the threeparttable package, its tnote macro, and its tablenotes environment.

    – Mico
    Feb 14 at 17:39











  • Thanks for the suggestions! I hadn't noticed the misalignment in column 2. Unfortunately for some reason I can't compile it in my document. Apparently there's an error with siunitx but I don't know why yet, Also thanks for pointing out the distnction with tabularx. I won't need it in this case but didn't know any better and just borrowed it from the code I had found. My bad!

    – egil137
    Feb 15 at 9:26











  • @egil137 - You mention experiencing "an an error with siunitx". What kind of error?

    – Mico
    Feb 15 at 9:36











  • well there are a few error first pointing for a missing or extra } inserted (which I don't think there is or haven't found) and the last error says: "Package siunitx Error: Invalid numerical input '='. end{tabularx}" I believe it might have to do with a conflicting package in my document? there are many, tried to "debug" but haven't found the culprit.

    – egil137
    Feb 15 at 10:14











  • Did you encase non-numeric cell contents in curly braces?

    – Mico
    Feb 15 at 10:20











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%2f474905%2ftrouble-with-formatting-a-tabularx-environment%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









2














You don't need tabularx, which is the wrong tool for a numeric table. Use tabular* and siunitx facilities.



I provide two realizations, the second one without extending the table up to the margins, which seems better.



documentclass{article}
usepackage{booktabs,siunitx}

sisetup{separate-uncertainty}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

begin{table}[htp]
centering

caption{Something that describes the table}label{whatever2}

begin{tabular}{
@{}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
@{}
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular}

end{table}

end{document}


enter image description here



You can center the header in the first column by using multicolumn{1}{c}{Probe} (or multicolumn{1}{@{}c}{Probe} for the second realization, where we remove the padding on the left of the first column).



I added also a trick for pulling the units nearer the header.



documentclass{article}
usepackage{amsmath,booktabs,siunitx}

sisetup{separate-uncertainty}

newcommand{tabhead}[1]{%
smash[b]{%
begin{tabular}[t]{@{}c@{}}#1end{tabular}%
}%
}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
multicolumn{1}{c}{Probe} &
{tabhead{MW \ (si{g/mol})}} &
{tabhead{R \ (si{nm})}} &
multicolumn{4}{c}{V (si{mL/g})} &
{tabhead{K \ (--)}} \
cmidrule{4-7}
&&& {1} & {2} & {3} & {avg.} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

end{document}


enter image description here






share|improve this answer





















  • 1





    I guess there might still be a rationale for using a tabularx rather than a tabular* environment: If the entries in the first column are a bit more descriptive, and a lot longer, than Label 1, Label 2, etc., it would be useful to assign the X column type to the first column and thus enable automatic line wrapping. At least, I would fervently hope that the real table's headers are a bit more informative than "Label 1", "Label 2", etc are...

    – Mico
    Feb 14 at 21:53











  • Thank you! didn't know the difference between tabular and tabularx. Any ideas how to center probe in the middle and make the other labels closer to the units? I'd like to reduce the white space between them.

    – egil137
    Feb 15 at 9:28











  • @egil137 I wouldn't center the header, but it's a stylistic choice. I added the other trick you asked for.

    – egreg
    Feb 15 at 9:37













  • Looks great! I have a new problem though :/ I'm working with a template and noticed that this line is preventing the correct spacing so it's preventing tabhead to work: renewcommand{baselinestretch}{1.5}. I would be afraid of removing this line and affecting some other formatting, or would this only affect tables?

    – egil137
    Feb 15 at 10:06











  • @egil137 Add renewcommand{arraystretch}{0.66667} in your document preamble, which will remove the stretching in tables.

    – egreg
    Feb 15 at 10:09
















2














You don't need tabularx, which is the wrong tool for a numeric table. Use tabular* and siunitx facilities.



I provide two realizations, the second one without extending the table up to the margins, which seems better.



documentclass{article}
usepackage{booktabs,siunitx}

sisetup{separate-uncertainty}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

begin{table}[htp]
centering

caption{Something that describes the table}label{whatever2}

begin{tabular}{
@{}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
@{}
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular}

end{table}

end{document}


enter image description here



You can center the header in the first column by using multicolumn{1}{c}{Probe} (or multicolumn{1}{@{}c}{Probe} for the second realization, where we remove the padding on the left of the first column).



I added also a trick for pulling the units nearer the header.



documentclass{article}
usepackage{amsmath,booktabs,siunitx}

sisetup{separate-uncertainty}

newcommand{tabhead}[1]{%
smash[b]{%
begin{tabular}[t]{@{}c@{}}#1end{tabular}%
}%
}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
multicolumn{1}{c}{Probe} &
{tabhead{MW \ (si{g/mol})}} &
{tabhead{R \ (si{nm})}} &
multicolumn{4}{c}{V (si{mL/g})} &
{tabhead{K \ (--)}} \
cmidrule{4-7}
&&& {1} & {2} & {3} & {avg.} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

end{document}


enter image description here






share|improve this answer





















  • 1





    I guess there might still be a rationale for using a tabularx rather than a tabular* environment: If the entries in the first column are a bit more descriptive, and a lot longer, than Label 1, Label 2, etc., it would be useful to assign the X column type to the first column and thus enable automatic line wrapping. At least, I would fervently hope that the real table's headers are a bit more informative than "Label 1", "Label 2", etc are...

    – Mico
    Feb 14 at 21:53











  • Thank you! didn't know the difference between tabular and tabularx. Any ideas how to center probe in the middle and make the other labels closer to the units? I'd like to reduce the white space between them.

    – egil137
    Feb 15 at 9:28











  • @egil137 I wouldn't center the header, but it's a stylistic choice. I added the other trick you asked for.

    – egreg
    Feb 15 at 9:37













  • Looks great! I have a new problem though :/ I'm working with a template and noticed that this line is preventing the correct spacing so it's preventing tabhead to work: renewcommand{baselinestretch}{1.5}. I would be afraid of removing this line and affecting some other formatting, or would this only affect tables?

    – egil137
    Feb 15 at 10:06











  • @egil137 Add renewcommand{arraystretch}{0.66667} in your document preamble, which will remove the stretching in tables.

    – egreg
    Feb 15 at 10:09














2












2








2







You don't need tabularx, which is the wrong tool for a numeric table. Use tabular* and siunitx facilities.



I provide two realizations, the second one without extending the table up to the margins, which seems better.



documentclass{article}
usepackage{booktabs,siunitx}

sisetup{separate-uncertainty}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

begin{table}[htp]
centering

caption{Something that describes the table}label{whatever2}

begin{tabular}{
@{}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
@{}
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular}

end{table}

end{document}


enter image description here



You can center the header in the first column by using multicolumn{1}{c}{Probe} (or multicolumn{1}{@{}c}{Probe} for the second realization, where we remove the padding on the left of the first column).



I added also a trick for pulling the units nearer the header.



documentclass{article}
usepackage{amsmath,booktabs,siunitx}

sisetup{separate-uncertainty}

newcommand{tabhead}[1]{%
smash[b]{%
begin{tabular}[t]{@{}c@{}}#1end{tabular}%
}%
}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
multicolumn{1}{c}{Probe} &
{tabhead{MW \ (si{g/mol})}} &
{tabhead{R \ (si{nm})}} &
multicolumn{4}{c}{V (si{mL/g})} &
{tabhead{K \ (--)}} \
cmidrule{4-7}
&&& {1} & {2} & {3} & {avg.} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

end{document}


enter image description here






share|improve this answer















You don't need tabularx, which is the wrong tool for a numeric table. Use tabular* and siunitx facilities.



I provide two realizations, the second one without extending the table up to the margins, which seems better.



documentclass{article}
usepackage{booktabs,siunitx}

sisetup{separate-uncertainty}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

begin{table}[htp]
centering

caption{Something that describes the table}label{whatever2}

begin{tabular}{
@{}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
@{}
}
toprule
Probe & {MW} & R & multicolumn{4}{c}{V (si{mL/g})} & {K} \
cmidrule{4-7}
& {(si{g/mol})} & {(si{nm})} & {1} & {2} & {3} & {avg.} & {(--)} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular}

end{table}

end{document}


enter image description here



You can center the header in the first column by using multicolumn{1}{c}{Probe} (or multicolumn{1}{@{}c}{Probe} for the second realization, where we remove the padding on the left of the first column).



I added also a trick for pulling the units nearer the header.



documentclass{article}
usepackage{amsmath,booktabs,siunitx}

sisetup{separate-uncertainty}

newcommand{tabhead}[1]{%
smash[b]{%
begin{tabular}[t]{@{}c@{}}#1end{tabular}%
}%
}

begin{document}

begin{table}[htp]

caption{Something that describes the table}label{whatever}

setlength{tabcolsep}{0pt}
begin{tabular*}{linewidth}{
@{extracolsep{fill}}
l
S[table-format=6.0,group-four-digits]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2(2)]
S[table-format=1.2]
}
toprule
multicolumn{1}{c}{Probe} &
{tabhead{MW \ (si{g/mol})}} &
{tabhead{R \ (si{nm})}} &
multicolumn{4}{c}{V (si{mL/g})} &
{tabhead{K \ (--)}} \
cmidrule{4-7}
&&& {1} & {2} & {3} & {avg.} \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 pm 0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 pm 0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 pm 0.42 & 1.00 \
bottomrule
end{tabular*}

end{table}

end{document}


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 15 at 9:37

























answered Feb 14 at 21:09









egregegreg

721k8719113210




721k8719113210








  • 1





    I guess there might still be a rationale for using a tabularx rather than a tabular* environment: If the entries in the first column are a bit more descriptive, and a lot longer, than Label 1, Label 2, etc., it would be useful to assign the X column type to the first column and thus enable automatic line wrapping. At least, I would fervently hope that the real table's headers are a bit more informative than "Label 1", "Label 2", etc are...

    – Mico
    Feb 14 at 21:53











  • Thank you! didn't know the difference between tabular and tabularx. Any ideas how to center probe in the middle and make the other labels closer to the units? I'd like to reduce the white space between them.

    – egil137
    Feb 15 at 9:28











  • @egil137 I wouldn't center the header, but it's a stylistic choice. I added the other trick you asked for.

    – egreg
    Feb 15 at 9:37













  • Looks great! I have a new problem though :/ I'm working with a template and noticed that this line is preventing the correct spacing so it's preventing tabhead to work: renewcommand{baselinestretch}{1.5}. I would be afraid of removing this line and affecting some other formatting, or would this only affect tables?

    – egil137
    Feb 15 at 10:06











  • @egil137 Add renewcommand{arraystretch}{0.66667} in your document preamble, which will remove the stretching in tables.

    – egreg
    Feb 15 at 10:09














  • 1





    I guess there might still be a rationale for using a tabularx rather than a tabular* environment: If the entries in the first column are a bit more descriptive, and a lot longer, than Label 1, Label 2, etc., it would be useful to assign the X column type to the first column and thus enable automatic line wrapping. At least, I would fervently hope that the real table's headers are a bit more informative than "Label 1", "Label 2", etc are...

    – Mico
    Feb 14 at 21:53











  • Thank you! didn't know the difference between tabular and tabularx. Any ideas how to center probe in the middle and make the other labels closer to the units? I'd like to reduce the white space between them.

    – egil137
    Feb 15 at 9:28











  • @egil137 I wouldn't center the header, but it's a stylistic choice. I added the other trick you asked for.

    – egreg
    Feb 15 at 9:37













  • Looks great! I have a new problem though :/ I'm working with a template and noticed that this line is preventing the correct spacing so it's preventing tabhead to work: renewcommand{baselinestretch}{1.5}. I would be afraid of removing this line and affecting some other formatting, or would this only affect tables?

    – egil137
    Feb 15 at 10:06











  • @egil137 Add renewcommand{arraystretch}{0.66667} in your document preamble, which will remove the stretching in tables.

    – egreg
    Feb 15 at 10:09








1




1





I guess there might still be a rationale for using a tabularx rather than a tabular* environment: If the entries in the first column are a bit more descriptive, and a lot longer, than Label 1, Label 2, etc., it would be useful to assign the X column type to the first column and thus enable automatic line wrapping. At least, I would fervently hope that the real table's headers are a bit more informative than "Label 1", "Label 2", etc are...

– Mico
Feb 14 at 21:53





I guess there might still be a rationale for using a tabularx rather than a tabular* environment: If the entries in the first column are a bit more descriptive, and a lot longer, than Label 1, Label 2, etc., it would be useful to assign the X column type to the first column and thus enable automatic line wrapping. At least, I would fervently hope that the real table's headers are a bit more informative than "Label 1", "Label 2", etc are...

– Mico
Feb 14 at 21:53













Thank you! didn't know the difference between tabular and tabularx. Any ideas how to center probe in the middle and make the other labels closer to the units? I'd like to reduce the white space between them.

– egil137
Feb 15 at 9:28





Thank you! didn't know the difference between tabular and tabularx. Any ideas how to center probe in the middle and make the other labels closer to the units? I'd like to reduce the white space between them.

– egil137
Feb 15 at 9:28













@egil137 I wouldn't center the header, but it's a stylistic choice. I added the other trick you asked for.

– egreg
Feb 15 at 9:37







@egil137 I wouldn't center the header, but it's a stylistic choice. I added the other trick you asked for.

– egreg
Feb 15 at 9:37















Looks great! I have a new problem though :/ I'm working with a template and noticed that this line is preventing the correct spacing so it's preventing tabhead to work: renewcommand{baselinestretch}{1.5}. I would be afraid of removing this line and affecting some other formatting, or would this only affect tables?

– egil137
Feb 15 at 10:06





Looks great! I have a new problem though :/ I'm working with a template and noticed that this line is preventing the correct spacing so it's preventing tabhead to work: renewcommand{baselinestretch}{1.5}. I would be afraid of removing this line and affecting some other formatting, or would this only affect tables?

– egil137
Feb 15 at 10:06













@egil137 Add renewcommand{arraystretch}{0.66667} in your document preamble, which will remove the stretching in tables.

– egreg
Feb 15 at 10:09





@egil137 Add renewcommand{arraystretch}{0.66667} in your document preamble, which will remove the stretching in tables.

– egreg
Feb 15 at 10:09











2














Some suggestions:





  • When using the tabularx environment, make sure to use at least one column of type X. For the table at hand, it seems OK to change the type of the first column from l to X. I'm assuming (hoping?!) that the "real" column labels will be more descriptive, and thus possibly also longer, than "Label 1", "Label 2", and "Label 3". If that's the case, it's useful to use the X column type for the first column as it allows automatic linebreaking. (The l column type does not.) In contrast, there would appear to be no scope for allowing line breaks in any of the other columns.



    The appearance of what looks like an empty column at the right-hand edge of your code is caused directly by the failure to use one or more columns of type X.



  • As you've discovered, using newline in a cell doesn't work. In the answer below, I propose a handy macro to typeset a header cell and associated units in a stacked format.


  • Optional: Consider using the siunitx package to (a) typeset scientific units properly (via he package's si macro) and (b) align the numbers in columns 2 and 3 on their (explicit or implicit) decimal markers (via the package's S column type).



enter image description here



documentclass{article}
usepackage{booktabs, tabularx, siunitx, xcolor}
sisetup{per-mode=symbol,group-digits=false}

%% handy utility macro:
newcommandsmalltab[1]{%
smash{begin{tabular}[t]{@{}c@{}} #1 end{tabular}}}

begin{document}

noindent
textcolor{red}{Before}

begin{center}
begin{tabularx}{linewidth}{@{} l r *{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

bigskipnoindent
textcolor{red}{After}

begin{center}
begin{tabularx}{linewidth}{@{} X
S[table-format=6.0] S[table-format=2.2] *{5}{c} @{}}
toprule
Probe & smalltab{MW\(si{grampermole})}
& smalltab{R\(si{nanometer})}
& multicolumn{4}{c}{V (si{milliliterpergram})}
& smalltab{K\(--)} \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32,${pm}$,0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

end{document}





share|improve this answer


























  • Regarding your "bonus" question: I suggest you look into the threeparttable package, its tnote macro, and its tablenotes environment.

    – Mico
    Feb 14 at 17:39











  • Thanks for the suggestions! I hadn't noticed the misalignment in column 2. Unfortunately for some reason I can't compile it in my document. Apparently there's an error with siunitx but I don't know why yet, Also thanks for pointing out the distnction with tabularx. I won't need it in this case but didn't know any better and just borrowed it from the code I had found. My bad!

    – egil137
    Feb 15 at 9:26











  • @egil137 - You mention experiencing "an an error with siunitx". What kind of error?

    – Mico
    Feb 15 at 9:36











  • well there are a few error first pointing for a missing or extra } inserted (which I don't think there is or haven't found) and the last error says: "Package siunitx Error: Invalid numerical input '='. end{tabularx}" I believe it might have to do with a conflicting package in my document? there are many, tried to "debug" but haven't found the culprit.

    – egil137
    Feb 15 at 10:14











  • Did you encase non-numeric cell contents in curly braces?

    – Mico
    Feb 15 at 10:20
















2














Some suggestions:





  • When using the tabularx environment, make sure to use at least one column of type X. For the table at hand, it seems OK to change the type of the first column from l to X. I'm assuming (hoping?!) that the "real" column labels will be more descriptive, and thus possibly also longer, than "Label 1", "Label 2", and "Label 3". If that's the case, it's useful to use the X column type for the first column as it allows automatic linebreaking. (The l column type does not.) In contrast, there would appear to be no scope for allowing line breaks in any of the other columns.



    The appearance of what looks like an empty column at the right-hand edge of your code is caused directly by the failure to use one or more columns of type X.



  • As you've discovered, using newline in a cell doesn't work. In the answer below, I propose a handy macro to typeset a header cell and associated units in a stacked format.


  • Optional: Consider using the siunitx package to (a) typeset scientific units properly (via he package's si macro) and (b) align the numbers in columns 2 and 3 on their (explicit or implicit) decimal markers (via the package's S column type).



enter image description here



documentclass{article}
usepackage{booktabs, tabularx, siunitx, xcolor}
sisetup{per-mode=symbol,group-digits=false}

%% handy utility macro:
newcommandsmalltab[1]{%
smash{begin{tabular}[t]{@{}c@{}} #1 end{tabular}}}

begin{document}

noindent
textcolor{red}{Before}

begin{center}
begin{tabularx}{linewidth}{@{} l r *{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

bigskipnoindent
textcolor{red}{After}

begin{center}
begin{tabularx}{linewidth}{@{} X
S[table-format=6.0] S[table-format=2.2] *{5}{c} @{}}
toprule
Probe & smalltab{MW\(si{grampermole})}
& smalltab{R\(si{nanometer})}
& multicolumn{4}{c}{V (si{milliliterpergram})}
& smalltab{K\(--)} \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32,${pm}$,0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

end{document}





share|improve this answer


























  • Regarding your "bonus" question: I suggest you look into the threeparttable package, its tnote macro, and its tablenotes environment.

    – Mico
    Feb 14 at 17:39











  • Thanks for the suggestions! I hadn't noticed the misalignment in column 2. Unfortunately for some reason I can't compile it in my document. Apparently there's an error with siunitx but I don't know why yet, Also thanks for pointing out the distnction with tabularx. I won't need it in this case but didn't know any better and just borrowed it from the code I had found. My bad!

    – egil137
    Feb 15 at 9:26











  • @egil137 - You mention experiencing "an an error with siunitx". What kind of error?

    – Mico
    Feb 15 at 9:36











  • well there are a few error first pointing for a missing or extra } inserted (which I don't think there is or haven't found) and the last error says: "Package siunitx Error: Invalid numerical input '='. end{tabularx}" I believe it might have to do with a conflicting package in my document? there are many, tried to "debug" but haven't found the culprit.

    – egil137
    Feb 15 at 10:14











  • Did you encase non-numeric cell contents in curly braces?

    – Mico
    Feb 15 at 10:20














2












2








2







Some suggestions:





  • When using the tabularx environment, make sure to use at least one column of type X. For the table at hand, it seems OK to change the type of the first column from l to X. I'm assuming (hoping?!) that the "real" column labels will be more descriptive, and thus possibly also longer, than "Label 1", "Label 2", and "Label 3". If that's the case, it's useful to use the X column type for the first column as it allows automatic linebreaking. (The l column type does not.) In contrast, there would appear to be no scope for allowing line breaks in any of the other columns.



    The appearance of what looks like an empty column at the right-hand edge of your code is caused directly by the failure to use one or more columns of type X.



  • As you've discovered, using newline in a cell doesn't work. In the answer below, I propose a handy macro to typeset a header cell and associated units in a stacked format.


  • Optional: Consider using the siunitx package to (a) typeset scientific units properly (via he package's si macro) and (b) align the numbers in columns 2 and 3 on their (explicit or implicit) decimal markers (via the package's S column type).



enter image description here



documentclass{article}
usepackage{booktabs, tabularx, siunitx, xcolor}
sisetup{per-mode=symbol,group-digits=false}

%% handy utility macro:
newcommandsmalltab[1]{%
smash{begin{tabular}[t]{@{}c@{}} #1 end{tabular}}}

begin{document}

noindent
textcolor{red}{Before}

begin{center}
begin{tabularx}{linewidth}{@{} l r *{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

bigskipnoindent
textcolor{red}{After}

begin{center}
begin{tabularx}{linewidth}{@{} X
S[table-format=6.0] S[table-format=2.2] *{5}{c} @{}}
toprule
Probe & smalltab{MW\(si{grampermole})}
& smalltab{R\(si{nanometer})}
& multicolumn{4}{c}{V (si{milliliterpergram})}
& smalltab{K\(--)} \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32,${pm}$,0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

end{document}





share|improve this answer















Some suggestions:





  • When using the tabularx environment, make sure to use at least one column of type X. For the table at hand, it seems OK to change the type of the first column from l to X. I'm assuming (hoping?!) that the "real" column labels will be more descriptive, and thus possibly also longer, than "Label 1", "Label 2", and "Label 3". If that's the case, it's useful to use the X column type for the first column as it allows automatic linebreaking. (The l column type does not.) In contrast, there would appear to be no scope for allowing line breaks in any of the other columns.



    The appearance of what looks like an empty column at the right-hand edge of your code is caused directly by the failure to use one or more columns of type X.



  • As you've discovered, using newline in a cell doesn't work. In the answer below, I propose a handy macro to typeset a header cell and associated units in a stacked format.


  • Optional: Consider using the siunitx package to (a) typeset scientific units properly (via he package's si macro) and (b) align the numbers in columns 2 and 3 on their (explicit or implicit) decimal markers (via the package's S column type).



enter image description here



documentclass{article}
usepackage{booktabs, tabularx, siunitx, xcolor}
sisetup{per-mode=symbol,group-digits=false}

%% handy utility macro:
newcommandsmalltab[1]{%
smash{begin{tabular}[t]{@{}c@{}} #1 end{tabular}}}

begin{document}

noindent
textcolor{red}{Before}

begin{center}
begin{tabularx}{linewidth}{@{} l r *{6}{c}}
toprule
Probe & MW newline (g/mol) & R newline (nm) & multicolumn{4}{c}{V (mL/g)} & K newline (--) \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1& 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 2& 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32 $pm$ 0.42 & 1.00 \
Label 3& 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32 $pm$ 0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

bigskipnoindent
textcolor{red}{After}

begin{center}
begin{tabularx}{linewidth}{@{} X
S[table-format=6.0] S[table-format=2.2] *{5}{c} @{}}
toprule
Probe & smalltab{MW\(si{grampermole})}
& smalltab{R\(si{nanometer})}
& multicolumn{4}{c}{V (si{milliliterpergram})}
& smalltab{K\(--)} \
cmidrule(lr){4-7}
& & & 1 & 2 & 3 & avg. & \
midrule
Label 1 & 400 & 0.00 & 0.00 & 2.34 & 12.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 2 & 10000 & 1.50 & 0.99 & 3.00 & 15.00 & 1.32,${pm}$,0.42 & 1.00 \
Label 3 & 500000 & 18.45 & 0.99 & 2.00 & 20.00 & 1.32,${pm}$,0.42 & 1.00 \
bottomrule
end{tabularx}
end{center}

end{document}






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 14 at 21:57

























answered Feb 14 at 17:31









MicoMico

279k31381770




279k31381770













  • Regarding your "bonus" question: I suggest you look into the threeparttable package, its tnote macro, and its tablenotes environment.

    – Mico
    Feb 14 at 17:39











  • Thanks for the suggestions! I hadn't noticed the misalignment in column 2. Unfortunately for some reason I can't compile it in my document. Apparently there's an error with siunitx but I don't know why yet, Also thanks for pointing out the distnction with tabularx. I won't need it in this case but didn't know any better and just borrowed it from the code I had found. My bad!

    – egil137
    Feb 15 at 9:26











  • @egil137 - You mention experiencing "an an error with siunitx". What kind of error?

    – Mico
    Feb 15 at 9:36











  • well there are a few error first pointing for a missing or extra } inserted (which I don't think there is or haven't found) and the last error says: "Package siunitx Error: Invalid numerical input '='. end{tabularx}" I believe it might have to do with a conflicting package in my document? there are many, tried to "debug" but haven't found the culprit.

    – egil137
    Feb 15 at 10:14











  • Did you encase non-numeric cell contents in curly braces?

    – Mico
    Feb 15 at 10:20



















  • Regarding your "bonus" question: I suggest you look into the threeparttable package, its tnote macro, and its tablenotes environment.

    – Mico
    Feb 14 at 17:39











  • Thanks for the suggestions! I hadn't noticed the misalignment in column 2. Unfortunately for some reason I can't compile it in my document. Apparently there's an error with siunitx but I don't know why yet, Also thanks for pointing out the distnction with tabularx. I won't need it in this case but didn't know any better and just borrowed it from the code I had found. My bad!

    – egil137
    Feb 15 at 9:26











  • @egil137 - You mention experiencing "an an error with siunitx". What kind of error?

    – Mico
    Feb 15 at 9:36











  • well there are a few error first pointing for a missing or extra } inserted (which I don't think there is or haven't found) and the last error says: "Package siunitx Error: Invalid numerical input '='. end{tabularx}" I believe it might have to do with a conflicting package in my document? there are many, tried to "debug" but haven't found the culprit.

    – egil137
    Feb 15 at 10:14











  • Did you encase non-numeric cell contents in curly braces?

    – Mico
    Feb 15 at 10:20

















Regarding your "bonus" question: I suggest you look into the threeparttable package, its tnote macro, and its tablenotes environment.

– Mico
Feb 14 at 17:39





Regarding your "bonus" question: I suggest you look into the threeparttable package, its tnote macro, and its tablenotes environment.

– Mico
Feb 14 at 17:39













Thanks for the suggestions! I hadn't noticed the misalignment in column 2. Unfortunately for some reason I can't compile it in my document. Apparently there's an error with siunitx but I don't know why yet, Also thanks for pointing out the distnction with tabularx. I won't need it in this case but didn't know any better and just borrowed it from the code I had found. My bad!

– egil137
Feb 15 at 9:26





Thanks for the suggestions! I hadn't noticed the misalignment in column 2. Unfortunately for some reason I can't compile it in my document. Apparently there's an error with siunitx but I don't know why yet, Also thanks for pointing out the distnction with tabularx. I won't need it in this case but didn't know any better and just borrowed it from the code I had found. My bad!

– egil137
Feb 15 at 9:26













@egil137 - You mention experiencing "an an error with siunitx". What kind of error?

– Mico
Feb 15 at 9:36





@egil137 - You mention experiencing "an an error with siunitx". What kind of error?

– Mico
Feb 15 at 9:36













well there are a few error first pointing for a missing or extra } inserted (which I don't think there is or haven't found) and the last error says: "Package siunitx Error: Invalid numerical input '='. end{tabularx}" I believe it might have to do with a conflicting package in my document? there are many, tried to "debug" but haven't found the culprit.

– egil137
Feb 15 at 10:14





well there are a few error first pointing for a missing or extra } inserted (which I don't think there is or haven't found) and the last error says: "Package siunitx Error: Invalid numerical input '='. end{tabularx}" I believe it might have to do with a conflicting package in my document? there are many, tried to "debug" but haven't found the culprit.

– egil137
Feb 15 at 10:14













Did you encase non-numeric cell contents in curly braces?

– Mico
Feb 15 at 10:20





Did you encase non-numeric cell contents in curly braces?

– Mico
Feb 15 at 10:20


















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%2f474905%2ftrouble-with-formatting-a-tabularx-environment%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

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?