6

I am trying to display a table containing two columns. The first displays an identifier and the second is an equation for that identifier. The table would look like this (if equations were allowed in tables, but this is not the main problem).

\begin{tabular}{|c|c|}
\hline
Clause & Input\\
\hline
Clause \ref{one} & \begin{equation} part1 \rightarrow (part2 \rightarrow part3)\end{equation}\\
Clause \ref{two} & \begin{equation} part1' \rightarrow (part2' \rightarrow part3')\end{equation}\\
\hline
\end{tabular}

The problem, is that part1 is similar to part1', part2 to part2', ... and I would like those sub-parts of the equations to be aligned. That is, something closer to this:

\begin{align}
\cline{1-4}
\text{Clause} & Input & & \\
\cline{1-4}
\text{Clause \ref{one}} & part1 & \rightarrow (part2 & \rightarrow part3)\\
\text{Clause \ref{two}} & part1' & \rightarrow (part2' & \rightarrow part3')\\
\cline{1-4}
\end{align}

But with this option, difficult to reproduce the tabular{|c|c|} formatting...

Is there a way to do this properly ? Or combine these environments ? Note: I really want to avoid setting any specific sizes (minipages, ...)


[EDIT]: I have found a solution that works. There is probably a nicer solution, but here is the full code:

enter image description here

\newcolumntype{E}{>{\refstepcounter{equation}(\theequation)}c}


\begin{tabular}{|c|lllE|}
\hline 
Clause & \multicolumn{4}{|c|}{$ctx$} \\
\hline
Clause \ref{clause:sas15:read} &
$v' = a[i]$ & $ \rightarrow ((v_a' = a[k_a'] \wedge i^{\#} =  i \wedge v'^{\#} =  v')$ & $ \rightarrow P_2^{\#}((k_a', v_a'), i^{\#}, v'^{\#}))$ & \label{eq:call:insts:read} \\
Clause \ref{clause:sas15:write} & $ a' = a[i \leftarrow v]$ & $ \rightarrow ((v_a' = a'[k_a'] \wedge i^{\#} =  i \wedge v^{\#} =  v)$ & $  \rightarrow P_2^{\#}((k_a', v_a'), i^{\#}, v^{\#})) $ & \label{eq:call:insts:write}\\
Clause \ref{clause:sas15:noarray} & $v' = 0$ & $ \rightarrow ((v_a' = a[k_a'] \wedge i^{\#} =  i \wedge v'^{\#} =  v )$ & $   \rightarrow P_2^{\#}((k_a', v_a'), i^{\#}, v'^{\#}))$ & \label{eq:call:insts:noarray}\\
\hline
\end{tabular}

I will keep the post open for a day in case someone has a nicer solution.

3
  • Welcome to tex.sx. You can use the "subsidiary" structure alignedat from amsmath within in-line math ($...$), which can be used within a table. Jan 16 at 1:37
  • I am not trying to write vertical lines over a \rightarrow. Perhaps the edit I made makes things clearer. As for alignedat, putting it into the tabular would not solve the problem: if the different equations are written in the same alignedat then there would be a mismatch with the Clause column.
    – SerkerN
    Jan 16 at 1:54
  • 2
    @SerkerN: Can you provide the full equation with details?
    – Werner
    Jan 16 at 2:13

3 Answers 3

4

Here's a solution that operates with a single tabular environment with a carefully constructed new math-mode column type called L and a bit of extra space to the left of the equation numbers.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters as needed

\usepackage{amsmath}
\usepackage{array} % for '\newcolumntype' macro
\newcolumntype{L}{>{$\displaystyle{}}l<{$}} % automatic display-style math mode
\newcolumntype{E}{>{\refstepcounter{equation}(\theequation)}r@{\hspace{2pt}}}

\begin{document}

\begin{center}
\renewcommand\arraystretch{1.5}
\begin{tabular}{| l | L@{}L@{}L @{\qquad} E |}
\hline 
Clause & \multicolumn{3}{c}{ctx} & \multicolumn{1}{c|}{} \\
\hline
\ref{clause:sas15:read} 
  & v' = a[i]  
  & \to ((v_a' = a[k_a'] \wedge i^{\#} =  i \wedge v'^{\#} =  v') 
  & \to P_2^{\#}((k_a', v_a'), i^{\#}, v'^{\#})) 
  & \label{eq:call:insts:read} \\
\ref{clause:sas15:write} 
  & a' = a[i \leftarrow v] 
  & \to ((v_a' = a'[k_a'] \wedge i^{\#} =  i \wedge v^{\#} =  v) 
  & \to P_2^{\#}((k_a', v_a'), i^{\#}, v^{\#}))  
  & \label{eq:call:insts:write}\\
\ref{clause:sas15:noarray} 
  & v' = 0 
  & \to ((v_a' = a[k_a'] \wedge i^{\#} =  i \wedge v'^{\#} =  v ) 
  & \to P_2^{\#}((k_a', v_a'), i^{\#}, v'^{\#})) 
  & \label{eq:call:insts:noarray} \\
\hline
\end{tabular}
\end{center}

\end{document}
4

Consider using boxes to find the widest element across equations. This method is simplified by eqparbox. Below I'm using \eqmathbox[<tag>][<align>]{<stuff>} to set all content with the same <tag> into a box of width matching the widest <stuff>. An additional <align>ment can be specified (left, right and center).

enter image description here

\documentclass{article}

\usepackage{amsmath,eqparbox}
\usepackage{array,booktabs}

\newcolumntype{E}{>{\refstepcounter{equation}(\theequation)}c}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
  \IfValueTF{#1}
    {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
    {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
  \mathpalette\eqmathbox@{#3}
}
\makeatother

\begin{document}

\begin{center}
  \begin{tabular}{ c l E }
    \toprule 
    Clause & \multicolumn{2}{c}{$ctx$} \\
    \midrule
    Clause 1 &
      $\eqmathbox[c1][l]{v' = a[i]} \rightarrow 
        \eqmathbox[c2][l]{\bigl( (v_a' = a[k_a'] \wedge i^{\#} = i \wedge v'^{\#} = v')} \rightarrow 
        \eqmathbox[c3][l]{P_2^{\#}((k_a', v_a'), i^{\#}, v'^{\#}) \bigr)}$ & \label{eq:call:insts:read} \\
    Clause 2 & 
      $\eqmathbox[c1][l]{a' = a[i \leftarrow v]} \rightarrow 
        \eqmathbox[c2][l]{\bigl( (v_a' = a'[k_a'] \wedge i^{\#} = i \wedge v^{\#} = v)} \rightarrow 
        \eqmathbox[c3][l]{P_2^{\#}((k_a', v_a'), i^{\#}, v^{\#}) \bigr)}$ & \label{eq:call:insts:write} \\
    Clause 3 & 
      $\eqmathbox[c1][l]{v' = 0} \rightarrow 
        \eqmathbox[c2][l]{\bigl( (v_a' = a[k_a'] \wedge i^{\#} = i \wedge v'^{\#} = v)} \rightarrow 
        \eqmathbox[c3][l]{P_2^{\#}((k_a', v_a'), i^{\#}, v'^{\#}) \bigr)}$ & \label{eq:call:insts:noarray} \\
    \bottomrule
  \end{tabular}
\end{center}

\end{document}
3

One may also use the IEEEeqnarraybox environment from the IEEEtrantools package. In the code

  • t is for centered "text" column (s and u for left and right aligned text respectively), l is for left aligned "math" column (c and r for centered and right aligned math respectively) and ? & / are for column separation.
  • IEEEeqnarrayrulerow is equivalent of hline with an optional argument of specifying the thickness of the rule whereas IEEEeqnarraymulticol is equivalent to multicolumn.
  • IEEEeqnarraydefcol is somewhat similar to newcolumntype. The syntax is \IEEEeqnarraydefcol{col_id}{predef}{postdef} where predef and postdef are like >{\command} and <{\command}.

(Code for equation is taken from Mico's answer.)

enter image description here

\documentclass{article}

\usepackage{amsmath}
\usepackage{IEEEtrantools}

\IEEEeqnarraydefcol{e}{\refstepcounter{equation}(\theequation)}{}

\begin{document}
\begin{table}[htbp]
    \footnotesize
    \centering
    \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutmode\IEEEeqnarraystrutsizeadd{2pt}{1pt}]{t?l/l/l/e}
        \IEEEeqnarrayrulerow[0.8pt]\\
        Clause & \IEEEeqnarraymulticol{4}{c}{ctx}\\
        \IEEEeqnarrayrulerow[0.5pt]\\
        Clause 1 
        & v' = a[i]  
        & \to ((v_a' = a[k_a'] \wedge i^{\#} =  i \wedge v'^{\#} =  v') 
        & \to P_2^{\#}((k_a', v_a'), i^{\#}, v'^{\#})) 
        & \label{eq:call:insts:read} \\
        Clause 2
        & a' = a[i \leftarrow v] 
        & \to ((v_a' = a'[k_a'] \wedge i^{\#} =  i \wedge v^{\#} =  v) 
        & \to P_2^{\#}((k_a', v_a'), i^{\#}, v^{\#}))  
        & \label{eq:call:insts:write}\\
        Clause 3 
        & v' = 0 
        & \to ((v_a' = a[k_a'] \wedge i^{\#} =  i \wedge v'^{\#} =  v ) 
        & \to P_2^{\#}((k_a', v_a'), i^{\#}, v'^{\#})) 
        & \label{eq:call:insts:noarray} \\
        \IEEEeqnarrayrulerow[0.8pt]%
    \end{IEEEeqnarraybox}
\end{table}
\end{document}

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.