2

So I know I can align columns by a comma with the dcolumn package like so:

\documentclass[12pt, a4paper]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{,}{#1}}
\begin{document}
\begin{tabular}{d{2} d{2}}
    \toprule
    $T\ $ [\si{\kelvin}] & $B\ $ [\si{\centi\meter\cubed\per\mole}] \\
    \midrule
    100 & -187,0 \\
    273 & -21,7 \\
    300 & -15,0 \\
    373 & -4,2 \\
    412 & 0,0 \\
    600 & 11,9 \\
    \bottomrule
\end{tabular}
\end{document}

Not the most minimal example, but it'll do. Now, I'd like to align columns by an equal sign instead of a comma. The problem seems to be related to the fact that the equal sign (=) is inside some inline math like $$.

A minimal example of this is:

\documentclass[12pt, a4paper]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{,}{#1}}
\begin{document}
\begin{tabular}{d{2} d{2}}
    $a = 1$ & $1 = 3$ \\
    $\int = 3$ & $ 7 = \sum 3$
\end{tabular}
\end{document}

A copy of the table I'm making can be found on pastebin Here (don't mind the warnings about margins & stuff) and looks like this: enter image description here

2

A solution without dcolumn:

\documentclass[12pt, a4paper]{article}
\usepackage{array}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{
  l
  *{4}{
    >{$}r<{$}
    @{}>{${}={}$}c@{}
    >{$}l<{$}
  }
}
  \toprule
  Process &
    \multicolumn{3}{c}{Indre energi $\Delta U$} &
    \multicolumn{3}{c}{Arbejde $w$} &
    \multicolumn{6}{c}{Betingelser} \\
  \midrule
  Isokor &
    \Delta U && n \cdot C_{V,m} \cdot \Delta T &
    w && 0 &
    \frac{p}{T} && \mbox{konst,} &
    \Delta V && 0 \\
  Isobar &
    \Delta U && n \cdot C_{V,m} \cdot \Delta T &
    w && -n \cdot R \cdot \Delta T &
    \frac{V}{T} && \mbox{konst,} &
    \Delta p && 0 \\
  Isoterm &
    \Delta U && 0 &
    w && -n \cdot R \cdot T \cdot \ln\frac{V_f}{V_i} &
    p \cdot V && \mbox{konst,} &
    \Delta T && 0 \\
  Adiabat &
    \Delta U && w &
    w && n \cdot C_{V,m} \cdot \delta T &
    p \cdot V^\gamma && \mbox{konst,} &
    \gamma && \frac{C_{p,m}}{C_{V,m}} \\
  \bottomrule
\end{tabular}
\end{document}

Result

  • Nice, a bit more complicated than first expected... I believe there was another answer involving dcolumn but it disapeared somehow. One thing; how can I get a the no-go vertical line between column 1 & 2? – Argo Sep 7 '15 at 17:48
  • @Argo Usually good tables do not have vertical lines. Add | (bar) after the first column specification l (lowercase L), then you get a line similar to the line in the question's image. – Heiko Oberdiek Sep 7 '15 at 17:56
  • I know, but in my opinion, it's ok in this situation. Thanks again. – Argo Sep 7 '15 at 18:00
  • @Argo The other answer was deleted by its owner. The alignment at the equals sign is easier with package dcolumn. But the difficult part is the centering without additional space at the left or right, and it is even more difficult, when arbitrary formulas are used. – Heiko Oberdiek Sep 7 '15 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.