Graphics, Figures & TablesCentering vertical lines in multicolumn

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
dickturnip
Posts: 12
Joined: Wed Nov 25, 2009 4:45 pm

Centering vertical lines in multicolumn

Post by dickturnip »

Hi.

I've not tried much with tables yet. What I would like to achieve is a heading spanning two columns with the line dividing columns below centered under this heading.

This is my minimum working example:

Code: Select all

\documentclass[]{article}

\usepackage{multicol}

\begin{document}

\begin{tabular}{c|c}
\multicolumn{2}{c}{Hello world,multicols}\\
6 & 7.4\\
5 & 5.3\\
3 & 3.5\\
\end{tabular}

\end{document}
if you run this you will see the integers are well over to the left, closely followed by the column divider.

I would like that column divider to be centered with the heading 'Hello world, multicols' and then the numbers to be centered with the space under the heading on either side of the column divider.

Can this be done easily?

Many thanks in advance,

Dicky

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10326
Joined: Mon Mar 10, 2008 9:44 pm

Centering vertical lines in multicolumn

Post by Stefan Kottwitz »

Hi Dicky,

that's no problem, for example:

Code: Select all

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{>{\centering}p{1.5cm}|>{\centering\arraybackslash}p{1.5cm}}
\multicolumn{2}{c}{Hello world,multicols}\\
6 & 7.4\\
5 & 5.3\\
3 & 3.5\\
\end{tabular}
\end{document}
You don't need the multicol package here.

Stefan
LaTeX.org admin
dickturnip
Posts: 12
Joined: Wed Nov 25, 2009 4:45 pm

Re: Centering vertical lines in multicolumn

Post by dickturnip »

Thank-you Stefan, that does it.

Dicky.
Post Reply