2

How do I align \angle in each cell, where \angle is inside separate inline math mode? Or another solution?

\begin{tabular}{|c|c|}
        \hline
        Frequency & $ C_{12}  $ $ (\mathrm{dB \ \angle \ deg}) $\\ \hline
        4.2 GHz    &  $ -15.64 \ \angle \ 38.26 $   \\ \hline
        4.6 GHz    &  $ -15.51 \ \angle \ -33.69 $   \\ \hline
        5.0 GHz    &  $ -17.70 \ \angle \ -93.28 $   \\ \hline
        5.4 GHz    &  $ -18.80 \ \angle \ -144.83 $   \\ \hline
    \end{tabular}
3

Perhaps you wish to align the numbers as well? Here are some options:

enter image description here

\documentclass{article}

\usepackage{array,eqparbox,collcell}

\newcommand{\setcolentryA}[1]{\eqmakebox[tabcol-\thetable][l]{#1}}
\def\splitanglerange$#1\angle#2${%
  \eqmakebox[tabcol-l-\thetable][r]{$#1$}%
  $\angle$%
  \eqmakebox[tabcol-r-\thetable][r]{$#2$}%
}
\newcommand{\setcolentryB}[1]{%
  \expandafter\splitanglerange#1%
}

\begin{document}

\begin{tabular}{ c c }
  \hline
  Frequency & $C_{12}\ (\mathrm{dB \ \angle \ deg})$ \\ 
  \hline
  4.2 GHz   &  $ -15.64 \ \angle \ 38.26 $   \\
  4.6 GHz   &  $ -15.51 \ \angle \ -33.69 $  \\
  5.0 GHz   &  $ -17.70 \ \angle \ -93.28 $  \\
  5.4 GHz   &  $ -18.80 \ \angle \ -144.83 $ \\
  \hline
\end{tabular}

\bigskip

\begin{tabular}{ c<{\ GHz} r @{\ $\angle$\ } r }
  \hline
  \multicolumn{1}{c}{Frequency} & \multicolumn{2}{c}{$C_{12}\ (\mathrm{dB \ \angle \ deg})$} \\ 
  \hline
  4.2 &  $-15.64$ &   $38.26$ \\
  4.6 &  $-15.51$ &  $-33.69$ \\
  5.0 &  $-17.70$ &  $-93.28$ \\
  5.4 &  $-18.80$ & $-144.83$ \\
  \hline
\end{tabular}

\bigskip

\begin{tabular}{ c<{\ GHz} >{\collectcell\setcolentryA}c<{\endcollectcell} }
  \hline
  \multicolumn{1}{c}{Frequency} & \multicolumn{1}{c}{$C_{12}\ (\mathrm{dB \ \angle \ deg})$} \\ 
  \hline
  4.2 & $-15.64 \ \angle \ 38.26$   \\
  4.6 & $-15.51 \ \angle \ {-}33.69$  \\
  5.0 & $-17.70 \ \angle \ {-}93.28$  \\
  5.4 & $-18.80 \ \angle \ {-}144.83$ \\
  \hline
\end{tabular}

\bigskip

\begin{tabular}{ c<{\ GHz} >{\collectcell\setcolentryB}c<{\endcollectcell} }
  \hline
  \multicolumn{1}{c}{Frequency} & \multicolumn{1}{c}{$C_{12}\ (\mathrm{dB \ \angle \ deg})$} \\ 
  \hline
  4.2 & $-15.64 \ \angle \ 38.26$   \\
  4.6 & $-15.51 \ \angle \ -33.69$  \\
  5.0 & $-17.70 \ \angle \ -93.28$  \\
  5.4 & $-18.80 \ \angle \ -144.83$ \\
  \hline
\end{tabular}

\end{document}

The first table represent the original setup.

The second table introduces a two-column layout for the "angle column". If you want the right "angle column" to be against the \angle, use l in the column specification instead of r.

The third table uses collcell to collect the column entries and insert them into a box which is measured by eqparbox's \eqmakebox[<tag>]. All boxes using the same <tag> are set with the same width. <tag> here is stepped with every table environment and should therefore be unique per table (not tabular).

The fourth table builds on the third by reverting back to the original two-column tabular. A macro extracts the content of the \angle column, separating out the lower and upper bounds, and then sets each in their own \eqmakebox[<l-tag>]-\eqmakebox[<r-tag>] box, thereby ensuring horizontal alignment.

Note that eqparbox uses the .aux file to store the box content, and therefore requires at least two compilation on the first go (or with any subsequent change in box content).

  • Can we do this without having extra columns? – Sup Feb 7 '17 at 19:08
  • @Sup: I've added some more options. – Werner Feb 7 '17 at 19:45
3

You should remove redundant information: if all entries in the first column are measurements in GHz, the unit should be in the header.

Here I show how to get the table in three ways; you may like the final one, where the extra column is masked off in the input by making \angle to work like &.

\documentclass{article}
\usepackage{booktabs} % for the better table
\usepackage{siunitx}

\begin{document}

\section{An ugly ruled table}

\begin{tabular}{
  |S[table-format=1.1]
  |S[table-format=-2.2]
  @{ $\angle$ }
   S[table-format=-3.2]|
  }
\hline
{Frequency}   & \multicolumn{2}{c|}{$C_{12}$} \\
{(\si{\GHz})} & \multicolumn{2}{c|}{(\si{\dB} $\angle$ \si{deg})} \\
\hline
4.2 & -15.64 &   38.26 \\ \hline
4.6 & -15.51 &  -33.69 \\ \hline
5.0 & -17.70 &  -93.28 \\ \hline
5.4 & -18.80 & -144.83 \\ \hline
\end{tabular}

\bigskip

\section{A better table}

\begin{tabular}{
  S[table-format=1.1]
  S[table-format=-2.2]
  @{ $\angle$ }
   S[table-format=-3.2]
  }
\toprule
{Frequency}   & \multicolumn{2}{c}{$C_{12}$} \\
{(\si{\GHz})} & \multicolumn{2}{c}{(\si{\dB} $\angle$ \si{deg})} \\
\midrule
4.2 & -15.64 &   38.26 \\
4.6 & -15.51 &  -33.69 \\
5.0 & -17.70 &  -93.28 \\
5.4 & -18.80 & -144.83 \\
\bottomrule
\end{tabular}

\section{Perhaps even better}

\begingroup
\let\mathangle=\angle
\let\angle=&
\begin{tabular}{
  S[table-format=1.1]
  S[table-format=-2.2]
  @{ $\mathangle$ }
   S[table-format=-3.2]
  }
\toprule
{Frequency}   & \multicolumn{2}{c}{$C_{12}$} \\
{(\si{\GHz})} & \multicolumn{2}{c}{(\si{\dB} $\mathangle$ \si{deg})} \\
\midrule
4.2 & -15.64 \angle   38.26 \\
4.6 & -15.51 \angle  -33.69 \\
5.0 & -17.70 \angle  -93.28 \\
5.4 & -18.80 \angle -144.83 \\
\bottomrule
\end{tabular}
\endgroup

\end{document}

The same trick can be used for the first model (but those rules are really bad, trust me).

enter image description here

  • Great. I'm trying to understand the code here. can you tell me the use of , \usepackage{booktabs} \usepackage{siunitx} and \begingroup \let\mathangle=\angle \let\angle=& \begin{tabular}{ S[table-format=1.1] S[table-format=-2.2] @{ $\mathangle$ } S[table-format=-3.2] } – Sup Feb 8 '17 at 17:59
  • 1
    @Sup booktabs is for the better table rules; siunitx for units and numeric tables. The trick in the last example is just showing off. ;-) – egreg Feb 8 '17 at 19:04

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.