Tabular align on equals sign












1















I'm pretty new to LaTeX, so sorry for the beginner question. I'm trying to align on equals signs within tabular, however a few rows are blank and don't have equals signs. How can I do this? Thanks!



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
begin{tabular}{|c|c|c|c|c|}
hline
Force Field & Calculated Energy & Calculated Difference & Experimental Difference & Error \
hline

multirow{4}{*}{OPLS-AA}
& tt = 2.55447 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = 4.19785 & $text{g}^+text{g}^+$-tt = 1.64338 & $text{g}^+text{g}^+$-tt = 1.62 & 0.02338 \ cline{2-5}
& $text{g}^+text{g}^-$ = 5.56306 & $text{g}^+text{g}^-$-tt = 3.00859 & $text{g}^+text{g}^-$-tt = 3.51 & -0.50141 \ cline{2-5}
& tg = 3.36156 & tg-tt = 0.80709 & tg-tt = 0.86 & -0.05291 \ cline{2-5}
hline

multirow{4}{*}{AM1}
& tt = -37.97281 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = -36.52659 & $text{g}^+text{g}^+$-tt = 1.44622 & $text{g}^+text{g}^+$-tt = 1.62 & -0.17378 \ cline{2-5}
& $text{g}^+text{g}^-$ = -35.85939 & $text{g}^+text{g}^-$-tt = 2.11342 & $text{g}^+text{g}^-$-tt = 3.51 & -1.39658 \ cline{2-5}
& tg = -37.25846 & tg-tt = 0.71435 & tg-tt = 0.86 & -0.14565 \ cline{2-5}
hline

multirow{4}{*}{PDDG/PM3}
& tt = -34.61227 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = -33.94462 & $text{g}^+text{g}^+$-tt = 0.66765 & $text{g}^+text{g}^+$-tt = 1.62 & -0.95235 \ cline{2-5}
& $text{g}^+text{g}^-$ = -33.29225 & $text{g}^+text{g}^-$-tt = 1.32002 & $text{g}^+text{g}^-$-tt = 3.51 & -2.18998 \ cline{2-5}
& tg = -34.38819 & tg-tt = 0.22408 & tg-tt = 0.86 & -0.63592 \ cline{2-5}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


Table Output



Edit: I don't think this post is duplicate, because my question concerns both aligning multicolumn over equals signs while still leaving certain lines without equal signs, which is not the case in the suggested duplicate.










share|improve this question









New contributor




David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Welcome to TeX.SE!

    – Kurt
    2 hours ago






  • 1





    Possible duplicate of Align Equations Over Multiple Tabular Rows

    – subham soni
    2 hours ago











  • @subhamsoni actually, you were right. I think this is pretty duplicate

    – David Lieberman
    39 mins ago
















1















I'm pretty new to LaTeX, so sorry for the beginner question. I'm trying to align on equals signs within tabular, however a few rows are blank and don't have equals signs. How can I do this? Thanks!



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
begin{tabular}{|c|c|c|c|c|}
hline
Force Field & Calculated Energy & Calculated Difference & Experimental Difference & Error \
hline

multirow{4}{*}{OPLS-AA}
& tt = 2.55447 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = 4.19785 & $text{g}^+text{g}^+$-tt = 1.64338 & $text{g}^+text{g}^+$-tt = 1.62 & 0.02338 \ cline{2-5}
& $text{g}^+text{g}^-$ = 5.56306 & $text{g}^+text{g}^-$-tt = 3.00859 & $text{g}^+text{g}^-$-tt = 3.51 & -0.50141 \ cline{2-5}
& tg = 3.36156 & tg-tt = 0.80709 & tg-tt = 0.86 & -0.05291 \ cline{2-5}
hline

multirow{4}{*}{AM1}
& tt = -37.97281 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = -36.52659 & $text{g}^+text{g}^+$-tt = 1.44622 & $text{g}^+text{g}^+$-tt = 1.62 & -0.17378 \ cline{2-5}
& $text{g}^+text{g}^-$ = -35.85939 & $text{g}^+text{g}^-$-tt = 2.11342 & $text{g}^+text{g}^-$-tt = 3.51 & -1.39658 \ cline{2-5}
& tg = -37.25846 & tg-tt = 0.71435 & tg-tt = 0.86 & -0.14565 \ cline{2-5}
hline

multirow{4}{*}{PDDG/PM3}
& tt = -34.61227 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = -33.94462 & $text{g}^+text{g}^+$-tt = 0.66765 & $text{g}^+text{g}^+$-tt = 1.62 & -0.95235 \ cline{2-5}
& $text{g}^+text{g}^-$ = -33.29225 & $text{g}^+text{g}^-$-tt = 1.32002 & $text{g}^+text{g}^-$-tt = 3.51 & -2.18998 \ cline{2-5}
& tg = -34.38819 & tg-tt = 0.22408 & tg-tt = 0.86 & -0.63592 \ cline{2-5}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


Table Output



Edit: I don't think this post is duplicate, because my question concerns both aligning multicolumn over equals signs while still leaving certain lines without equal signs, which is not the case in the suggested duplicate.










share|improve this question









New contributor




David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Welcome to TeX.SE!

    – Kurt
    2 hours ago






  • 1





    Possible duplicate of Align Equations Over Multiple Tabular Rows

    – subham soni
    2 hours ago











  • @subhamsoni actually, you were right. I think this is pretty duplicate

    – David Lieberman
    39 mins ago














1












1








1


1






I'm pretty new to LaTeX, so sorry for the beginner question. I'm trying to align on equals signs within tabular, however a few rows are blank and don't have equals signs. How can I do this? Thanks!



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
begin{tabular}{|c|c|c|c|c|}
hline
Force Field & Calculated Energy & Calculated Difference & Experimental Difference & Error \
hline

multirow{4}{*}{OPLS-AA}
& tt = 2.55447 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = 4.19785 & $text{g}^+text{g}^+$-tt = 1.64338 & $text{g}^+text{g}^+$-tt = 1.62 & 0.02338 \ cline{2-5}
& $text{g}^+text{g}^-$ = 5.56306 & $text{g}^+text{g}^-$-tt = 3.00859 & $text{g}^+text{g}^-$-tt = 3.51 & -0.50141 \ cline{2-5}
& tg = 3.36156 & tg-tt = 0.80709 & tg-tt = 0.86 & -0.05291 \ cline{2-5}
hline

multirow{4}{*}{AM1}
& tt = -37.97281 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = -36.52659 & $text{g}^+text{g}^+$-tt = 1.44622 & $text{g}^+text{g}^+$-tt = 1.62 & -0.17378 \ cline{2-5}
& $text{g}^+text{g}^-$ = -35.85939 & $text{g}^+text{g}^-$-tt = 2.11342 & $text{g}^+text{g}^-$-tt = 3.51 & -1.39658 \ cline{2-5}
& tg = -37.25846 & tg-tt = 0.71435 & tg-tt = 0.86 & -0.14565 \ cline{2-5}
hline

multirow{4}{*}{PDDG/PM3}
& tt = -34.61227 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = -33.94462 & $text{g}^+text{g}^+$-tt = 0.66765 & $text{g}^+text{g}^+$-tt = 1.62 & -0.95235 \ cline{2-5}
& $text{g}^+text{g}^-$ = -33.29225 & $text{g}^+text{g}^-$-tt = 1.32002 & $text{g}^+text{g}^-$-tt = 3.51 & -2.18998 \ cline{2-5}
& tg = -34.38819 & tg-tt = 0.22408 & tg-tt = 0.86 & -0.63592 \ cline{2-5}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


Table Output



Edit: I don't think this post is duplicate, because my question concerns both aligning multicolumn over equals signs while still leaving certain lines without equal signs, which is not the case in the suggested duplicate.










share|improve this question









New contributor




David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I'm pretty new to LaTeX, so sorry for the beginner question. I'm trying to align on equals signs within tabular, however a few rows are blank and don't have equals signs. How can I do this? Thanks!



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
begin{tabular}{|c|c|c|c|c|}
hline
Force Field & Calculated Energy & Calculated Difference & Experimental Difference & Error \
hline

multirow{4}{*}{OPLS-AA}
& tt = 2.55447 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = 4.19785 & $text{g}^+text{g}^+$-tt = 1.64338 & $text{g}^+text{g}^+$-tt = 1.62 & 0.02338 \ cline{2-5}
& $text{g}^+text{g}^-$ = 5.56306 & $text{g}^+text{g}^-$-tt = 3.00859 & $text{g}^+text{g}^-$-tt = 3.51 & -0.50141 \ cline{2-5}
& tg = 3.36156 & tg-tt = 0.80709 & tg-tt = 0.86 & -0.05291 \ cline{2-5}
hline

multirow{4}{*}{AM1}
& tt = -37.97281 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = -36.52659 & $text{g}^+text{g}^+$-tt = 1.44622 & $text{g}^+text{g}^+$-tt = 1.62 & -0.17378 \ cline{2-5}
& $text{g}^+text{g}^-$ = -35.85939 & $text{g}^+text{g}^-$-tt = 2.11342 & $text{g}^+text{g}^-$-tt = 3.51 & -1.39658 \ cline{2-5}
& tg = -37.25846 & tg-tt = 0.71435 & tg-tt = 0.86 & -0.14565 \ cline{2-5}
hline

multirow{4}{*}{PDDG/PM3}
& tt = -34.61227 & && \ cline{2-5}
& $text{g}^+text{g}^+$ = -33.94462 & $text{g}^+text{g}^+$-tt = 0.66765 & $text{g}^+text{g}^+$-tt = 1.62 & -0.95235 \ cline{2-5}
& $text{g}^+text{g}^-$ = -33.29225 & $text{g}^+text{g}^-$-tt = 1.32002 & $text{g}^+text{g}^-$-tt = 3.51 & -2.18998 \ cline{2-5}
& tg = -34.38819 & tg-tt = 0.22408 & tg-tt = 0.86 & -0.63592 \ cline{2-5}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


Table Output



Edit: I don't think this post is duplicate, because my question concerns both aligning multicolumn over equals signs while still leaving certain lines without equal signs, which is not the case in the suggested duplicate.







tables math-mode align multicolumn






share|improve this question









New contributor




David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago







David Lieberman













New contributor




David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









David LiebermanDavid Lieberman

83




83




New contributor




David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






David Lieberman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Welcome to TeX.SE!

    – Kurt
    2 hours ago






  • 1





    Possible duplicate of Align Equations Over Multiple Tabular Rows

    – subham soni
    2 hours ago











  • @subhamsoni actually, you were right. I think this is pretty duplicate

    – David Lieberman
    39 mins ago



















  • Welcome to TeX.SE!

    – Kurt
    2 hours ago






  • 1





    Possible duplicate of Align Equations Over Multiple Tabular Rows

    – subham soni
    2 hours ago











  • @subhamsoni actually, you were right. I think this is pretty duplicate

    – David Lieberman
    39 mins ago

















Welcome to TeX.SE!

– Kurt
2 hours ago





Welcome to TeX.SE!

– Kurt
2 hours ago




1




1





Possible duplicate of Align Equations Over Multiple Tabular Rows

– subham soni
2 hours ago





Possible duplicate of Align Equations Over Multiple Tabular Rows

– subham soni
2 hours ago













@subhamsoni actually, you were right. I think this is pretty duplicate

– David Lieberman
39 mins ago





@subhamsoni actually, you were right. I think this is pretty duplicate

– David Lieberman
39 mins ago










1 Answer
1






active

oldest

votes


















1














Here is one approach. I split the columns using = into two columns. To get the spacing right (and save typing) I used @{$null=null$} between the columns. Unfortunately, this meant having to use multicolumn every time I didn't want a = to appear.



The only remaining problem was that when the label is too large, the extra space is added to the right half. To fix that, I calculated the difference and added extra space to the left half using makebox. Now the equal signs are centered.



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
sbox0{Calculated Difference}%
sbox1{Experimental Difference}%
sbox2{$null=null$}%
dimen0=dimexpr 0.5wd0 - 0.5wd2relax
dimen1=dimexpr 0.5wd1 - 0.5wd2relax
begin{tabular}{|c|r@{$null=null$}l|r@{$null=null$}l|r@{$null=null$}l|c|}
hline
Force Field & multicolumn{2}{c|}{Calculated Energy} & multicolumn{2}{c|}{Calculated Difference} & multicolumn{2}{c|}{Experimental Difference} & Error \
hline
multirow{4}{*}{OPLS-AA}
& tt & 2.55447 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & 4.19785 & makebox[dimen0][r]{$text{g}^+text{g}^+$-tt} & 1.64338
& makebox[dimen1][r]{$text{g}^+text{g}^+$-tt} & 1.62 & 0.02338 \ cline{2-8}% note makebox
& $text{g}^+text{g}^-$ & 5.56306 & $text{g}^+text{g}^-$-tt & 3.00859 & $text{g}^+text{g}^-$-tt & 3.51 & -0.50141 \ cline{2-8}
& tg & 3.36156 & tg-tt & 0.80709 & tg-tt & 0.86 & -0.05291 \ cline{2-8}
hline

multirow{4}{*}{AM1}
& tt & -37.97281 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -36.52659 & $text{g}^+text{g}^+$-tt & 1.44622 & $text{g}^+text{g}^+$-tt & 1.62 & -0.17378 \ cline{2-8}
& $text{g}^+text{g}^-$ & -35.85939 & $text{g}^+text{g}^-$-tt & 2.11342 & $text{g}^+text{g}^-$-tt & 3.51 & -1.39658 \ cline{2-8}
& tg & -37.25846 & tg-tt & 0.71435 & tg-tt & 0.86 & -0.14565 \ cline{2-8}
hline
multirow{4}{*}{PDDG/PM3}
& tt & -34.61227 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -33.94462 & $text{g}^+text{g}^+$-tt & 0.66765 & $text{g}^+text{g}^+$-tt & 1.62 & -0.95235 \ cline{2-8}
& $text{g}^+text{g}^-$ & -33.29225 & $text{g}^+text{g}^-$-tt & 1.32002 & $text{g}^+text{g}^-$-tt & 3.51 & -2.18998 \ cline{2-8}
& tg & -34.38819 & tg-tt & 0.22408 & tg-tt & 0.86 & -0.63592 \ cline{2-8}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


demo






share|improve this answer


























  • Great! Is there a way to maintain the text being centered, like under the "Experimental Difference" column? (I see that you're splitting left/right on the equals sign, so I understand that might not be possible)

    – David Lieberman
    1 hour ago













  • Possible, but you need to locate the largest item to the left of the = and the largest item to the right (not necessarily in the same row). I was hoping centering the = was good enough. After all, siunitx only centers the decimal point.

    – John Kormylo
    1 hour ago











  • Ah, I see. Thank you! I'll mark this as solved.

    – David Lieberman
    1 hour ago











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
});


}
});






David Lieberman is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f480817%2ftabular-align-on-equals-sign%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









1














Here is one approach. I split the columns using = into two columns. To get the spacing right (and save typing) I used @{$null=null$} between the columns. Unfortunately, this meant having to use multicolumn every time I didn't want a = to appear.



The only remaining problem was that when the label is too large, the extra space is added to the right half. To fix that, I calculated the difference and added extra space to the left half using makebox. Now the equal signs are centered.



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
sbox0{Calculated Difference}%
sbox1{Experimental Difference}%
sbox2{$null=null$}%
dimen0=dimexpr 0.5wd0 - 0.5wd2relax
dimen1=dimexpr 0.5wd1 - 0.5wd2relax
begin{tabular}{|c|r@{$null=null$}l|r@{$null=null$}l|r@{$null=null$}l|c|}
hline
Force Field & multicolumn{2}{c|}{Calculated Energy} & multicolumn{2}{c|}{Calculated Difference} & multicolumn{2}{c|}{Experimental Difference} & Error \
hline
multirow{4}{*}{OPLS-AA}
& tt & 2.55447 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & 4.19785 & makebox[dimen0][r]{$text{g}^+text{g}^+$-tt} & 1.64338
& makebox[dimen1][r]{$text{g}^+text{g}^+$-tt} & 1.62 & 0.02338 \ cline{2-8}% note makebox
& $text{g}^+text{g}^-$ & 5.56306 & $text{g}^+text{g}^-$-tt & 3.00859 & $text{g}^+text{g}^-$-tt & 3.51 & -0.50141 \ cline{2-8}
& tg & 3.36156 & tg-tt & 0.80709 & tg-tt & 0.86 & -0.05291 \ cline{2-8}
hline

multirow{4}{*}{AM1}
& tt & -37.97281 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -36.52659 & $text{g}^+text{g}^+$-tt & 1.44622 & $text{g}^+text{g}^+$-tt & 1.62 & -0.17378 \ cline{2-8}
& $text{g}^+text{g}^-$ & -35.85939 & $text{g}^+text{g}^-$-tt & 2.11342 & $text{g}^+text{g}^-$-tt & 3.51 & -1.39658 \ cline{2-8}
& tg & -37.25846 & tg-tt & 0.71435 & tg-tt & 0.86 & -0.14565 \ cline{2-8}
hline
multirow{4}{*}{PDDG/PM3}
& tt & -34.61227 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -33.94462 & $text{g}^+text{g}^+$-tt & 0.66765 & $text{g}^+text{g}^+$-tt & 1.62 & -0.95235 \ cline{2-8}
& $text{g}^+text{g}^-$ & -33.29225 & $text{g}^+text{g}^-$-tt & 1.32002 & $text{g}^+text{g}^-$-tt & 3.51 & -2.18998 \ cline{2-8}
& tg & -34.38819 & tg-tt & 0.22408 & tg-tt & 0.86 & -0.63592 \ cline{2-8}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


demo






share|improve this answer


























  • Great! Is there a way to maintain the text being centered, like under the "Experimental Difference" column? (I see that you're splitting left/right on the equals sign, so I understand that might not be possible)

    – David Lieberman
    1 hour ago













  • Possible, but you need to locate the largest item to the left of the = and the largest item to the right (not necessarily in the same row). I was hoping centering the = was good enough. After all, siunitx only centers the decimal point.

    – John Kormylo
    1 hour ago











  • Ah, I see. Thank you! I'll mark this as solved.

    – David Lieberman
    1 hour ago
















1














Here is one approach. I split the columns using = into two columns. To get the spacing right (and save typing) I used @{$null=null$} between the columns. Unfortunately, this meant having to use multicolumn every time I didn't want a = to appear.



The only remaining problem was that when the label is too large, the extra space is added to the right half. To fix that, I calculated the difference and added extra space to the left half using makebox. Now the equal signs are centered.



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
sbox0{Calculated Difference}%
sbox1{Experimental Difference}%
sbox2{$null=null$}%
dimen0=dimexpr 0.5wd0 - 0.5wd2relax
dimen1=dimexpr 0.5wd1 - 0.5wd2relax
begin{tabular}{|c|r@{$null=null$}l|r@{$null=null$}l|r@{$null=null$}l|c|}
hline
Force Field & multicolumn{2}{c|}{Calculated Energy} & multicolumn{2}{c|}{Calculated Difference} & multicolumn{2}{c|}{Experimental Difference} & Error \
hline
multirow{4}{*}{OPLS-AA}
& tt & 2.55447 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & 4.19785 & makebox[dimen0][r]{$text{g}^+text{g}^+$-tt} & 1.64338
& makebox[dimen1][r]{$text{g}^+text{g}^+$-tt} & 1.62 & 0.02338 \ cline{2-8}% note makebox
& $text{g}^+text{g}^-$ & 5.56306 & $text{g}^+text{g}^-$-tt & 3.00859 & $text{g}^+text{g}^-$-tt & 3.51 & -0.50141 \ cline{2-8}
& tg & 3.36156 & tg-tt & 0.80709 & tg-tt & 0.86 & -0.05291 \ cline{2-8}
hline

multirow{4}{*}{AM1}
& tt & -37.97281 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -36.52659 & $text{g}^+text{g}^+$-tt & 1.44622 & $text{g}^+text{g}^+$-tt & 1.62 & -0.17378 \ cline{2-8}
& $text{g}^+text{g}^-$ & -35.85939 & $text{g}^+text{g}^-$-tt & 2.11342 & $text{g}^+text{g}^-$-tt & 3.51 & -1.39658 \ cline{2-8}
& tg & -37.25846 & tg-tt & 0.71435 & tg-tt & 0.86 & -0.14565 \ cline{2-8}
hline
multirow{4}{*}{PDDG/PM3}
& tt & -34.61227 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -33.94462 & $text{g}^+text{g}^+$-tt & 0.66765 & $text{g}^+text{g}^+$-tt & 1.62 & -0.95235 \ cline{2-8}
& $text{g}^+text{g}^-$ & -33.29225 & $text{g}^+text{g}^-$-tt & 1.32002 & $text{g}^+text{g}^-$-tt & 3.51 & -2.18998 \ cline{2-8}
& tg & -34.38819 & tg-tt & 0.22408 & tg-tt & 0.86 & -0.63592 \ cline{2-8}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


demo






share|improve this answer


























  • Great! Is there a way to maintain the text being centered, like under the "Experimental Difference" column? (I see that you're splitting left/right on the equals sign, so I understand that might not be possible)

    – David Lieberman
    1 hour ago













  • Possible, but you need to locate the largest item to the left of the = and the largest item to the right (not necessarily in the same row). I was hoping centering the = was good enough. After all, siunitx only centers the decimal point.

    – John Kormylo
    1 hour ago











  • Ah, I see. Thank you! I'll mark this as solved.

    – David Lieberman
    1 hour ago














1












1








1







Here is one approach. I split the columns using = into two columns. To get the spacing right (and save typing) I used @{$null=null$} between the columns. Unfortunately, this meant having to use multicolumn every time I didn't want a = to appear.



The only remaining problem was that when the label is too large, the extra space is added to the right half. To fix that, I calculated the difference and added extra space to the left half using makebox. Now the equal signs are centered.



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
sbox0{Calculated Difference}%
sbox1{Experimental Difference}%
sbox2{$null=null$}%
dimen0=dimexpr 0.5wd0 - 0.5wd2relax
dimen1=dimexpr 0.5wd1 - 0.5wd2relax
begin{tabular}{|c|r@{$null=null$}l|r@{$null=null$}l|r@{$null=null$}l|c|}
hline
Force Field & multicolumn{2}{c|}{Calculated Energy} & multicolumn{2}{c|}{Calculated Difference} & multicolumn{2}{c|}{Experimental Difference} & Error \
hline
multirow{4}{*}{OPLS-AA}
& tt & 2.55447 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & 4.19785 & makebox[dimen0][r]{$text{g}^+text{g}^+$-tt} & 1.64338
& makebox[dimen1][r]{$text{g}^+text{g}^+$-tt} & 1.62 & 0.02338 \ cline{2-8}% note makebox
& $text{g}^+text{g}^-$ & 5.56306 & $text{g}^+text{g}^-$-tt & 3.00859 & $text{g}^+text{g}^-$-tt & 3.51 & -0.50141 \ cline{2-8}
& tg & 3.36156 & tg-tt & 0.80709 & tg-tt & 0.86 & -0.05291 \ cline{2-8}
hline

multirow{4}{*}{AM1}
& tt & -37.97281 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -36.52659 & $text{g}^+text{g}^+$-tt & 1.44622 & $text{g}^+text{g}^+$-tt & 1.62 & -0.17378 \ cline{2-8}
& $text{g}^+text{g}^-$ & -35.85939 & $text{g}^+text{g}^-$-tt & 2.11342 & $text{g}^+text{g}^-$-tt & 3.51 & -1.39658 \ cline{2-8}
& tg & -37.25846 & tg-tt & 0.71435 & tg-tt & 0.86 & -0.14565 \ cline{2-8}
hline
multirow{4}{*}{PDDG/PM3}
& tt & -34.61227 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -33.94462 & $text{g}^+text{g}^+$-tt & 0.66765 & $text{g}^+text{g}^+$-tt & 1.62 & -0.95235 \ cline{2-8}
& $text{g}^+text{g}^-$ & -33.29225 & $text{g}^+text{g}^-$-tt & 1.32002 & $text{g}^+text{g}^-$-tt & 3.51 & -2.18998 \ cline{2-8}
& tg & -34.38819 & tg-tt & 0.22408 & tg-tt & 0.86 & -0.63592 \ cline{2-8}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


demo






share|improve this answer















Here is one approach. I split the columns using = into two columns. To get the spacing right (and save typing) I used @{$null=null$} between the columns. Unfortunately, this meant having to use multicolumn every time I didn't want a = to appear.



The only remaining problem was that when the label is too large, the extra space is added to the right half. To fix that, I calculated the difference and added extra space to the left half using makebox. Now the equal signs are centered.



documentclass{article}
usepackage[utf8]{inputenc}
usepackage{multirow, adjustbox, mathtools}
begin{document}

begin{table}[htbp]
begin{adjustbox}{width=columnwidth,center}
sbox0{Calculated Difference}%
sbox1{Experimental Difference}%
sbox2{$null=null$}%
dimen0=dimexpr 0.5wd0 - 0.5wd2relax
dimen1=dimexpr 0.5wd1 - 0.5wd2relax
begin{tabular}{|c|r@{$null=null$}l|r@{$null=null$}l|r@{$null=null$}l|c|}
hline
Force Field & multicolumn{2}{c|}{Calculated Energy} & multicolumn{2}{c|}{Calculated Difference} & multicolumn{2}{c|}{Experimental Difference} & Error \
hline
multirow{4}{*}{OPLS-AA}
& tt & 2.55447 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & 4.19785 & makebox[dimen0][r]{$text{g}^+text{g}^+$-tt} & 1.64338
& makebox[dimen1][r]{$text{g}^+text{g}^+$-tt} & 1.62 & 0.02338 \ cline{2-8}% note makebox
& $text{g}^+text{g}^-$ & 5.56306 & $text{g}^+text{g}^-$-tt & 3.00859 & $text{g}^+text{g}^-$-tt & 3.51 & -0.50141 \ cline{2-8}
& tg & 3.36156 & tg-tt & 0.80709 & tg-tt & 0.86 & -0.05291 \ cline{2-8}
hline

multirow{4}{*}{AM1}
& tt & -37.97281 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -36.52659 & $text{g}^+text{g}^+$-tt & 1.44622 & $text{g}^+text{g}^+$-tt & 1.62 & -0.17378 \ cline{2-8}
& $text{g}^+text{g}^-$ & -35.85939 & $text{g}^+text{g}^-$-tt & 2.11342 & $text{g}^+text{g}^-$-tt & 3.51 & -1.39658 \ cline{2-8}
& tg & -37.25846 & tg-tt & 0.71435 & tg-tt & 0.86 & -0.14565 \ cline{2-8}
hline
multirow{4}{*}{PDDG/PM3}
& tt & -34.61227 & multicolumn{2}{c|}{} & multicolumn{2}{c|}{} & \ cline{2-8}
& $text{g}^+text{g}^+$ & -33.94462 & $text{g}^+text{g}^+$-tt & 0.66765 & $text{g}^+text{g}^+$-tt & 1.62 & -0.95235 \ cline{2-8}
& $text{g}^+text{g}^-$ & -33.29225 & $text{g}^+text{g}^-$-tt & 1.32002 & $text{g}^+text{g}^-$-tt & 3.51 & -2.18998 \ cline{2-8}
& tg & -34.38819 & tg-tt & 0.22408 & tg-tt & 0.86 & -0.63592 \ cline{2-8}
hline
end{tabular}
end{adjustbox}
end{table}

end{document}


demo







share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 2 hours ago









John KormyloJohn Kormylo

45.8k22672




45.8k22672













  • Great! Is there a way to maintain the text being centered, like under the "Experimental Difference" column? (I see that you're splitting left/right on the equals sign, so I understand that might not be possible)

    – David Lieberman
    1 hour ago













  • Possible, but you need to locate the largest item to the left of the = and the largest item to the right (not necessarily in the same row). I was hoping centering the = was good enough. After all, siunitx only centers the decimal point.

    – John Kormylo
    1 hour ago











  • Ah, I see. Thank you! I'll mark this as solved.

    – David Lieberman
    1 hour ago



















  • Great! Is there a way to maintain the text being centered, like under the "Experimental Difference" column? (I see that you're splitting left/right on the equals sign, so I understand that might not be possible)

    – David Lieberman
    1 hour ago













  • Possible, but you need to locate the largest item to the left of the = and the largest item to the right (not necessarily in the same row). I was hoping centering the = was good enough. After all, siunitx only centers the decimal point.

    – John Kormylo
    1 hour ago











  • Ah, I see. Thank you! I'll mark this as solved.

    – David Lieberman
    1 hour ago

















Great! Is there a way to maintain the text being centered, like under the "Experimental Difference" column? (I see that you're splitting left/right on the equals sign, so I understand that might not be possible)

– David Lieberman
1 hour ago







Great! Is there a way to maintain the text being centered, like under the "Experimental Difference" column? (I see that you're splitting left/right on the equals sign, so I understand that might not be possible)

– David Lieberman
1 hour ago















Possible, but you need to locate the largest item to the left of the = and the largest item to the right (not necessarily in the same row). I was hoping centering the = was good enough. After all, siunitx only centers the decimal point.

– John Kormylo
1 hour ago





Possible, but you need to locate the largest item to the left of the = and the largest item to the right (not necessarily in the same row). I was hoping centering the = was good enough. After all, siunitx only centers the decimal point.

– John Kormylo
1 hour ago













Ah, I see. Thank you! I'll mark this as solved.

– David Lieberman
1 hour ago





Ah, I see. Thank you! I'll mark this as solved.

– David Lieberman
1 hour ago










David Lieberman is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















David Lieberman is a new contributor. Be nice, and check out our Code of Conduct.













David Lieberman is a new contributor. Be nice, and check out our Code of Conduct.












David Lieberman is a new contributor. Be nice, and check out our Code of Conduct.
















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%2f480817%2ftabular-align-on-equals-sign%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

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks