0

I have the following code that generates a table

\begin{tabular}{|c|c|c|c|} \hline
    \multicolumn{4}{|c|}{A} \\ \hline
    \multicolumn{2}{|c}{B} & \multicolumn{2}{|c|}{C} \\ \hline 
       D & E & F & G \\ \hline
         &   &   &   \\ \hline
\end{tabular}

It works well except for the fact that there is a very minor shift in the alignment of the columns (see image below). I can't see why this is happening. Anyone know of a solution?

Column alignment error


EDIT: A simple fix: moving the divider character from the start of the C label to the end of the B label.

\begin{tabular}{|c|c|c|c|} \hline
    \multicolumn{4}{|c|}{A} \\ \hline
    \multicolumn{2}{|c|}{B} & \multicolumn{2}{c|}{C} \\ \hline 
       D & E & F & G \\ \hline
         &   &   &   \\ \hline
\end{tabular}
  • I just ran it and it seems to be all right, two questions, have you tried zoom in and out (maybe a rendering deal with your pdf viewer)? can you please provide a MWE? – Hans Mar 5 '15 at 19:44
  • It looks like you've already found the solution. Is that right? – Mico Mar 5 '15 at 19:45
  • Your solution (edit) is correct, since the \multicolumn column specification allows you to have independent vertical rules for each cell... and since multiple vertical rules are allowed, you the location of | is important. – Werner Mar 5 '15 at 19:48
2

I have found the solution to my own question. It seems that (as Werner pointed out), since \multicolumn allows for independent vertical rules for each cell, the location of the divider character, |, will change the appearance of the overall table, as seen in the figure in the above question.

The solution is to ensure that you are consistent with the location of the alignment character. Modifying the original code slightly to read

\begin{tabular}{|c|c|c|c|} \hline
    \multicolumn{4}{|c|}{A} \\ \hline
    \multicolumn{2}{|c|}{B} & \multicolumn{2}{c|}{C} \\ \hline 
       D & E & F & G \\ \hline
         &   &   &   \\ \hline
\end{tabular}

yields the following (aligned) table:

enter image description here

| improve this answer | |

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.