Align over many rows in table

How can I do an alignment with the = characters for a=1, abbbbbb=5 and csf=6 ?

It should look like this but inside the table:

      a=1
abbbbbb=5234
csf=6


My code is:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{positioning}
\usepackage{flowchart}
\usetikzlibrary{arrows}
\usepackage{fix-cm}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\setlength{\heavyrulewidth}{1.5pt}
\setlength{\abovetopsep}{4pt}
\usepackage{amsmath}

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|}
\hline
\multicolumn{1}{|l|}{a } & looooooooooong \\
\hline
\multirow{3}[6]{*}{c} & a=1  \\
\cline{2-2}          & abbbbbb=5234  \\
\cline{2-2}          & csf = 6  \\
\hline
\end{tabular}%
\end{table}%

\end{document}


What I tried (but didn't work):

   \documentclass{article}

\usepackage[table]{xcolor}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{positioning}
\usepackage{flowchart}
\usetikzlibrary{arrows}
\usepackage{fix-cm}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\setlength{\heavyrulewidth}{1.5pt}
\setlength{\abovetopsep}{4pt}
\usepackage{amsmath}

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|}
\hline
\multicolumn{1}{|l|}{a } & looooooooooong \\
\hline
\multirow{3}[6]{*}{c} &\begin{align} a&=1  \\
\cline{2-2}          & abbbbbb&=5234  \\
\cline{2-2}          & csf &= 6 \end{align} \\
\hline
\end{tabular}%
\end{table}%

\end{document}


I hope someone can help me. I searched a bit in the forums but it all the solution seem to be so complicated for a quite simple problem like this. Also it's Tex so there should be a nice analytic solution I hope cause I need this feature quite often in my tables.

• Use two columns: {r@{=}l} – John Kormylo Sep 27 '17 at 22:22
• hello thank you for your answer. i'm quite a beginner. Can you specify what you mean? So there no way of using a classic alignenviroment? – myname Sep 27 '17 at 22:25
• why do you want the equations in a table? it seems a slightly odd requirement. – David Carlisle Sep 27 '17 at 22:40
• you could have an align inside the table but (most easily) without the horizontal rules, do you need the rules? If the equations are related and need alignment you wouldn't normally put in rules to separate them. – David Carlisle Sep 27 '17 at 22:43
• @David Carlisle no i don't need them. I want to write a protokoll Specification. There need to be one colummn in one row which contains about 4 rows (\multirow) where i'll write in the first row 1=message, in the second row 2=information. message and informationwill have different widths and since it the rows will be under each other it looks bad if i don't align them. – myname Sep 27 '17 at 23:09

The following solution is a refinement of @JohnKormylo's suggestion: change the tabular setup from 2 to 3 columns, and have LaTeX insert = (type mathrel, in math mode) automatically between columns 2 and 3. That way, the spacing around the = symbol will automatically be appropriate for math-mode material.

\documentclass{article}
\usepackage{array,amsmath,multirow}
\newcommand\mc[1]{\multicolumn{2}{c|}{#1}} % handy shortcut macro
\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{| c | r @{${}={}$} l |}
\hline
\multicolumn{1}{|l|}{a} & \mc{looooooooooong} \\ \hline
\multirow{3}{*}{cc} & a       & 1    \\ \cline{2-3}
& abbbbbb & 5234 \\ \cline{2-3}
& csf     & 6    \\ \hline
\end{tabular}
\end{table}
\end{document}

• Beat me by 4 miniuts! – John Kormylo Sep 27 '17 at 23:12

How about a solution with only two rows, and an aligned environment? For the horizontal rules inside the aligned environment, I use the capability of \cmidrule to extend on both sides with the (lr) argument. This is obtained with a rather simple code. The 0.95em lengthening of \cmidrule was found by trial and error:

\documentclass{article}
\usepackage{array,amsmath}
\usepackage{booktabs}

\begin{document}

\begin{table}[htbp]
\centering\setlength{\aboverulesep}{0pt}\setlength{\belowrulesep}{0pt}
\begin{tabular}{| c |c|}
\hline
a & looooooooooong\\ \hline
c & \begin{aligned} a & = 1 \\ \cmidrule(l{-0.95em} r{-0.95em}){1-3} abbbbbb & = 5234 \\ \cmidrule(l{-0.95em} r{-0.95em}){1-3} csf & = 6 \end{aligned} \\ \hline
\end{tabular}
\end{table}

\end{document}


• For the benefit of readers who maybe aren't all that familiar with the facilities of the booktabs package, could you add a brief description of how you came up with -0.95em as the length value to be passed to the trimming options of \cmidrule? – Mico Sep 28 '17 at 7:18
• @Mico: Done, mylord! The sole benefit, I think, will be to understand what l{some length} and r{some length} mean in the syntax of \cmidrule. – Bernard Sep 28 '17 at 8:19
• Thank you this is what i was searching originally for :) I'll still stick with the three column version cause on the right side of the equal i will write a word and therefor non italic or \verb||style looks better – myname Sep 28 '17 at 14:23
• You can write words with \text{some words} or \texttt inside math mode… – Bernard Sep 28 '17 at 14:28

Here are two ways using overlapping of content (since it looks like it should be math, I've used \mathllap and \mathrlap from mathtools), or boxing them into similar-sized boxes (using eqparbox):

\documentclass{article}

\usepackage{mathtools,eqparbox}

\begin{document}

\begin{tabular}{|c|c|}
\hline
a & looooooooooong   \\
\hline
& $a = 1$          \\
\cline{2-2}
& $abbbbbb = 5234$ \\
\cline{2-2}
c & $csf = 6$        \\
\hline
\begin{tabular}{|c|c|}
\hline
a & looooooooooong   \\
\hline
& $\phantom{abbbbbb}\mathllap{a} = \mathrlap{1}\phantom{5234}$   \\
\cline{2-2}
& $abbbbbb = 5234$ \\
\cline{2-2}
c & $\phantom{abbbbbb}\mathllap{csf} = \mathrlap{6}\phantom{5234}$ \\
\hline
\begin{tabular}{|c|c|}
\hline
a & looooooooooong   \\
\hline
& $\eqmakebox[lhs][r]{$a$} = \eqmakebox[rhs][l]{$1$}$    \\
\cline{2-2}
& $\eqmakebox[lhs]{$abbbbbb$} = \eqmakebox[rhs]{$5234$}$ \\
\cline{2-2}
c & $\eqmakebox[lhs][r]{$csf$} = \eqmakebox[rhs][l]{$6$}$  \\
\hline
\end{tabular}

\end{document}

• Thank you for your answer :) i'll stick with the other three column answer cause it fits my needs best – myname Sep 28 '17 at 14:25