23

I can't figure out how to merge two rows as in figure below.

This is my code:

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}             
\usepackage[english,italian]{babel}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}

\begin{document}
\title{Title}
\author{Me}
%\date{10 dicembre 2015}

\maketitle

 \begin{center}
  \begin{tabular}{|c|c|}
\hline
Text & \\
\hline 
Diametro fori (mm) & 4\\
\hline 
Passo x (mm) & 24\\
\hline
Passo y (mm) & 24\\
\hline
Altezza canale (mm) & 10\\
\hline
Lunghezza canale (mm) & 146\\
\hline
Numero fori & 39\\
\hline
  \end{tabular}
   \captionof{table}{Caratteristiche della piastra e del canale}
    \label{tab:dati_canale-piastra}
 \end{center}

\end{document}

enter image description here

2
  • 1
    You actually merge cels from two adjacent columns (concluded from your picture)
    – Zarko
    Dec 13 '15 at 18:25
  • 2
    If one of the answers fits your needs, consider to accept them please
    – user31729
    Feb 9 '18 at 21:45
22

Try \multicolumn{2}{|l|}{Text} \tabularnewline in the relevant row. \multicolumn{n}{q}{foo} merges n cells with type q and places foo as content.

Side note: Using booktabs and vertical lines in a table is not the best design. I would also use left alignment for the first column.

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}             
\usepackage[english,italian]{babel}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}

\begin{document}
  \title{Title}
  \author{Me}
  %\date{10 dicembre 2015}

  \maketitle

  \begin{center}
    \begin{tabular}{|c|c|}
      \hline
      \multicolumn{2}{|l|}{Text} \tabularnewline
      \hline 
      Diametro fori (mm) & 4 \tabularnewline
      \hline 
      Passo x (mm) & 24\tabularnewline
      \hline
      Passo y (mm) & 24\tabularnewline
      \hline
      Altezza canale (mm) & 10\tabularnewline
      \hline
      Lunghezza canale (mm) & 146\tabularnewline
      \hline
      Numero fori & 39\tabularnewline
      \hline
    \end{tabular}
    \captionof{table}{Caratteristiche della piastra e del canale}
    \label{tab:dati_canale-piastra}
  \end{center}
\end{document}

enter image description here

6

Since you're already loading the booktabs package, you should give serious thought to improving the overall "look" of the table by (a) getting rid of all vertical lines, (b) getting rid of most horizontal lines, and (c) using the macros \toprule, \midrule, and \bottomrule of the booktabs package for the remaining three horizontal lines. With these changes in place, figuring out how to get rid of the unwanted central vertical divider in the header row becomes unnecessary. Note that, in the table below, I also suggest not using c (centering) for both columns; instead, I recommend l (left-alignment) for the first column and r (right-alignment) for the second column.

enter image description here

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}             
\usepackage[english,italian]{babel}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[bindingoffset=1.5cm, margin=3cm]{geometry}

\begin{document}

\begin{center}
\begin{tabular}{@{} lr @{}}
\toprule
Text  \\
\midrule
Diametro fori (mm) & 4\\
Passo x (mm) & 24\\
Passo y (mm) & 24\\
Altezza canale (mm) & 10\\
Lunghezza canale (mm) & 146\\
Numero fori & 39\\
\bottomrule
\end{tabular}
\captionof{table}{Caratteristiche della piastra e del canale}
\label{tab:dati_canale-piastra}
\end{center}

\end{document}
0
4

You have to use multicolumn command:

\documentclass{book}
\begin{document}

\begin{table}
\begin{tabular}{|c|c|}
\multicolumn{2}{|c|}{\textbf{TITLE}} \\\hline
Value1 & Value2 \\\hline
Value1 & Value2 \\\hline
Value1 & Value2 \\\hline
\end{tabular}
\end{table}

\end{document}

UPDATE: As correctly mentioned below, you don't need the multirow package to use the multicolumn command.

5
  • 2
    For multicolumn you not need `multirow package ...
    – Zarko
    Dec 13 '15 at 18:24
  • 1
    The c specifier should be |c| most likely
    – user31729
    Dec 13 '15 at 18:31
  • Good points! You are right! Dec 13 '15 at 18:43
  • 1
    @MarcoMoschettini: Well, there's no multicolumn package ;-)
    – user31729
    Dec 13 '15 at 18:49
  • You may also want to explain in more detail your choice of using a table environment where the OP used a center environment, as well as the choice not to center the contents of the table environment.
    – Mico
    Dec 13 '15 at 18:50

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.