2

Beginner's question: Why doesn't horizontal alignment work as I expect in this simple table? I just have a set of variables with values in the left column which I want to align under the heading "Givet"(=Given) and a set of variables which are sought in the right column which I want to align under the heading "Sökt". It either complains that I should use "math accents in math mode" or it complains that I am missing a # or a &.

\halign{       #&#&#                & \quad\hfil    #&#                 \cr
\it{Givet}\rm   &{}&{}              &               {}&\it{S\"okt}\rm   \cr
$\varphi_{m}$   &=&0.4              &               {}&$\dot{V_{o}}$    \cr
$t_{m}$         &=&$21^{\rm{o}}$C   &               {}&$\Delta i_{o}$   \cr
$t_{o}$         &=&$0^{\rm{o}}$C    &               {}&$\t_{o}'$        \cr
$\varphi_{o}$   &=&0.7              &               {}&{}               \cr
$t_{2}$         &=&$24^{\rm{o}}$C   &               {}&{}               \cr
$\varphi_{2}$   &=&0.5              &               {}&{}               \cr
p               &=&1.013 bar        &               {}&{}               \cr

}

2 Answers 2

4

I think you want something like

enter image description here

\halign{\hfil#\unskip&${}#{}$&#\unskip\hfil   & \quad\hfil    #&#\unskip\hfil   \cr
\multispan{2}{\it Givet}&{}              &               {}&\it S\"okt   \cr
$\varphi_{m}$   &=&0.4              &               {}&$\dot{V_{o}}$    \cr
$t_{m}$         &=&$21^{\rm o}$C   &               {}&$\Delta i_{o}$   \cr
$t_{o}$         &=&$0^{\rm o}$C    &               {}&$t_{o}'$        \cr
$\varphi_{o}$   &=&0.7              &               {}&{}               \cr
$t_{2}$         &=&$24^{\rm o}$C   &               {}&{}               \cr
$\varphi_{2}$   &=&0.5              &               {}&{}               \cr
p               &=&1.013 bar        &               {}&{}               \cr
}


\bigskip

\halign{#\unskip\hfil&${}#{}$&#\hfil                & \quad\hfil    #&#\hfil    \cr
\multispan{2}{\it Givet}&{}              &               {}&\it S\"okt   \cr
$\varphi_{m}$   &=&0.4              &               {}&$\dot{V_{o}}$    \cr
$t_{m}$         &=&$21^{\rm o}$C   &               {}&$\Delta i_{o}$   \cr
$t_{o}$         &=&$0^{\rm o}$C    &               {}&$t_{o}'$        \cr
$\varphi_{o}$   &=&0.7              &               {}&{}               \cr
$t_{2}$         &=&$24^{\rm o}$C   &               {}&{}               \cr
$\varphi_{2}$   &=&0.5              &               {}&{}               \cr
p               &=&1.013 bar        &               {}&{}               \cr
}

\bigskip

\halign{#\unskip\hfil                & \quad\hfil    #&#\unskip\hfil      \cr
\it Givet               &               {}&\it S\"okt   \cr
$\varphi_{m}   =0.4 $             &               {}&$\dot{V_{o}}$    \cr
$t_{m}         =21^{\rm o}{\rm C}$   &               {}&$\Delta i_{o}$   \cr
$t_{o}        =0^{\rm o}{\rm C}$    &               {}&$t_{o}'$        \cr
$\varphi_{o}   =0.7    $          &               {}&{}               \cr
$t_{2}       =24^{\rm o}{\rm C}$   &               {}&{}               \cr
$\varphi_{2}   =0.5$              &               {}&{}               \cr
${\rm p}               =1.013 \,{\rm bar}$        &               {}&{}               \cr
}

\bye

Note I added glue to all columns to give alignment, forced math spacing for =, and \rm and \it do not take an argument so I removed the { } brace groups.

The error about accents is due to \t which I think is just a typo for t here so I changed it to that.

6
  • @david-carslie Nice! And if I want the left column variables be flush left but =-sign still aligned under each other? Commented May 9, 2022 at 16:28
  • 1
    put the hfil to the right of the #, but then you get uneven space around the = @LasseKaragiannis Commented May 9, 2022 at 16:39
  • 1
    @LasseKaragiannis I can not understand what you want. If you align the = then you either right align the first column or have unevn space. That is not a latex issue it's just geometry, If you want left aligned but with equal space around = then just use one column not 3, you can left align a=1, b=2, ... and have equal space around = but the = not aligned. All are easy to do, just decide which you want. Commented May 9, 2022 at 18:10
  • 1
    @LasseKaragiannis I added three versions in the answer Commented May 9, 2022 at 18:17
  • 1
    ah maybe you wanted multispan, i just updaed again @LasseKaragiannis Commented May 9, 2022 at 18:20
4

Beware that TeX ignores spaces after &, but not before it. If you want to be precise about spacing between columns, you need to avoid those spaces.

In the code below the spaces are there, but they're ignored due to math mode in the cells, which also avoids the orgy of $ characters in the body.

\def\celsius{{}^\circ{\rm C}}
\def\bar{{\rm bar}}

\tabskip=0pt
\halign{%
  $#$\hfil&
  ${}#{}$&
  $#$\hfil&
  \quad$#$\hfil\cr
\multispan{3}\it Givet\hfil &\multispan{1}\quad\it S\"okt\hfil\cr
\varphi_{m} &=& 0.4          & \dot{V_{o}}  \cr
t_{m}       &=& 21\,\celsius & \Delta i_{o} \cr
t_{o}       &=& 0\,\celsius  & t_{o}'       \cr
\varphi_{o} &=& 0.7              \cr
t_{2}       &=& 24\,\celsius     \cr
\varphi_{2} &=& 0.5              \cr
p           &=& 1.013\,\bar \cr
}

\bye

Note \multispan to join cells in the first row (or simply to override the template for one column).

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .