Best way to merge columns and rows in tables with column separators

  • Context: LaTeX 
  • Thread starter Thread starter Wrichik Basu
  • Start date Start date
  • Tags Tags
    Column Columns Table
Click For Summary
SUMMARY

The discussion focuses on merging columns and rows in LaTeX tables using the multicolumn and multirow commands from the multirow package. The user encountered issues when merging columns that included separators, resulting in unexpected output. A manual workaround was provided, positioning the text correctly without using multirow. The conversation seeks more efficient methods for merging rows and columns in LaTeX tables while maintaining proper formatting.

PREREQUISITES
  • Familiarity with LaTeX table formatting
  • Understanding of the multicolumn command
  • Knowledge of the multirow package
  • Basic skills in LaTeX syntax and commands
NEXT STEPS
  • Explore advanced LaTeX table formatting techniques
  • Learn about the array package for more complex table structures
  • Investigate the use of the booktabs package for improved table aesthetics
  • Research LaTeX documentation on table merging commands
USEFUL FOR

LaTeX users, academic writers, and anyone involved in document preparation who needs to create complex tables with merged cells and proper formatting.

Wrichik Basu
Science Advisor
Insights Author
Gold Member
Messages
2,186
Reaction score
2,694
For merging columns, I generally use the multicolumn command, while for merging rows, I use the multirow command from the multirow package.

The above combination works great if there is no separator in any of the merged columns. If, however, one or more columns have separators, the code breaks.

Consider the following code snippet:
[CODE title="LaTeX"]\begin{table}[h]
\centering
\begin{tabular}{|l|c c c|c c c c|}
\hline
col1 & col2 & col3 & col4 & col5 & col6 & col7 & col8\\
\hline
row1 & j & k & l & x & y & z & aa\\
row2 & \multicolumn{7}{c|}{\multirow{3}{*}{a very long sentence that I want to type}}\\
row3 & & & & & & & \\
row4 & & & & & & & \\
row5 & q & r & s & t & u & v & bb \\
\hline
\end{tabular}
\end{table}[/CODE]
And I get the following output:

1601031345063.png

What I wanted is that the long text will be placed in the middle of rows 2 to 4, and the separator will be removed by at that point.

What ##\LaTeX## is doing instead is that multicolumn is merging all the columns in row2, and then multirow is positioning the text somewhere in the middle. So, the point where the separator is removed is not the place where the text is placed.

I can do this "manually" by positioning the text at the correct position myself instead of using multirow to do that:
[CODE title="LaTeX"]\begin{table}[h]
\centering
\begin{tabular}{|l|c c c|c c c c|}
\hline
col1 & col2 & col3 & col4 & col5 & col6 & col7 & col8\\
\hline
row1 & j & k & l & x & y & z & aa \\
row2 & & & & & & & \\
row3 & \multicolumn{7}{c|}{a very long sentence that I want to type} \\
row4 & & & & & & & \\
row5 & q & r & s & t & u & v & bb \\
\hline
\end{tabular}
\end{table}[/CODE]
This gives the following table:
1601032078511.png
which is what I wanted.

Is there any better way of merging rows and columns in these cases?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 9 ·
Replies
9
Views
7K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
3
Views
3K