3

I am trying to make a table that has some cells spanning across multiple lines, like this:Table that I want

(I used print screen on my table and then edited it to show how I want it).

I have been searching around and didn't find a way to do it, though I have seen similar problems but couldn't apply their solution to mine.

This is the code I am using:

\begin{table}
    \caption{Funções e conexões do conector X1}
\begin{center}
\begin{tabular}{|c|l|l|}
    \hline
    \textbf{X1} &\textbf{Descrição} &\textbf{Função} \\
    \hline
    1   &C      &Saída digital 1 \\
    \hline
    2   &NA     &a relé \\
    \hline
    3   &Dl1        &Entradas digitais \\
    \hline
    4   &Dl2        &optoacopladas \\
    \hline
    5   &COM 1,2    &1 e 2 \\
    \hline
    6   &Dl3        &Entrada digital 3 \\
    \hline
    7   &COM3           &optoacoplada \\
    \hline
    8   &Al1 +          &Entrada analógica 1 \\
    \hline
    9   &Al1 -      &diferencial \\
    \hline
\end{tabular}
\end{center}
\end{table}

Thanks for the help.

1
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – cfr
    Apr 16, 2014 at 22:14

2 Answers 2

2

The simplest way is to just not draw full horizontal lines when you want to combine rows:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}

\begin{document}

\begin{table}
  \caption{Funções e conexões do conector X1}
  \centering
  \begin{tabular}{|c|l|l|}
      \hline
      \textbf{X1} &\textbf{Descrição} &\textbf{Função} \\\hline
      1   &C      &Saída digital 1 \\\cline{1-2}
      2   &NA     & a relé\\\hline
      3   &Dl1        &Entradas digitais\\\cline{1-2}
      4   &Dl2        & optoacopladas\\\hline
      5   &COM 1,2    &1 e 2 \\\cline{1-2}
      6   &Dl3        &Entrada digital 3 \\\cline{1-2}
      7   &COM3           &optoacoplada \\\hline
      8   &Al1 +          &Entrada analógica 1 \\\cline{1-2}
      9   &Al1 -      &diferencial \\\hline
  \end{tabular}
\end{table}
\begin{table}
  \caption{Funções e conexões do conector X1}
  \centering
  \begin{tabular}{cll}
      \toprule
      \textbf{X1} &\textbf{Descrição} &\textbf{Função} \\\midrule
      1   &C      &Saída digital 1 \\\cmidrule{1-2}
      2   &NA     & a relé \\\midrule
      3   &Dl1        &Entradas digitais \\\cmidrule{1-2}
      4   &Dl2        & optoacopladas \\\midrule
      5   &COM 1,2    &1 e 2 \\\cmidrule{1-2}
      6   &Dl3        &Entrada digital 3 \\\cmidrule{1-2}
      7   &COM3           &optoacoplada \\\midrule
      8   &Al1 +          &Entrada analógica 1 \\\cmidrule{1-2}
      9   &Al1 -      &diferencial \\\bottomrule
  \end{tabular}
\end{table}


\end{document}

The second tabular shows how to reformat the table in accordance with the guidelines set out in booktabs (or some of them anyway).

Tabulars

Or you could remove the partial horizontal lines altogether if you took this approach:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}

\begin{document}

\begin{table}
  \caption{Funções e conexões do conector X1}
  \centering
  \begin{tabular}{cll}
      \toprule
      \textbf{X1} &\textbf{Descrição} &\textbf{Função} \\\midrule
      1   &C      &Saída digital 1 \\
      2   &NA     & a relé \\\midrule
      3   &Dl1        &Entradas digitais \\
      4   &Dl2        & optoacopladas \\\midrule
      5   &COM 1,2    &1 e 2 \\
      6   &Dl3        &Entrada digital 3 \\
      7   &COM3           &optoacoplada \\\midrule
      8   &Al1 +          &Entrada analógica 1 \\
      9   &Al1 -      &diferencial \\\bottomrule
  \end{tabular}
\end{table}


\end{document}

Most minimal

3
  • @GonzaloMedina Actually, I'm not sure. I can't tell. Is it obvious that the text in the right-most column goes together (1&2, 3&4, 5&6&7, 8&9) or might it be read as belonging on each line individually?
    – cfr
    Apr 16, 2014 at 22:31
  • @GonzaloMedina I've added it as an example so the OP can judge what's best. The 3 line combination I worry about especially since the 2nd line starts with a capital. (I don't know why but it is not my language so I'm dealing with mere strings.)
    – cfr
    Apr 16, 2014 at 22:35
  • @GonzaloMedina Thanks for yours! And I think providing both options is definitely best here.
    – cfr
    Apr 16, 2014 at 22:41
0

The makecell package is just for multilined cells (whether multirow or not). In addition, just using horizontal lines, as pointed above, loks much better. In addition, using the rule commands from booktabs gives some spacing to the cells. I also use the caption package: just loading it gives a better vertical spacing between the caption and the table. As another comment, you shouldn't use the center environment here: it adds its own vertical spacing to the one provided by table.

    \documentclass{article}

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage{caption}
    \usepackage{booktabs}
    \usepackage{multirow}
    \usepackage{makecell}
    \renewcommand{\theadfont}{\bfseries}
    \renewcommand{\cellalign}{lc}

    \begin{document}

 \begin{table}
%\renewcommand{\arraystretch}{1.5}
\centering
    \caption{Funções e conexões do conector X1}
\begin{tabular}{cll}
    \toprule
    \thead{X1} &\thead{Descrição} &\thead{Função} \\
    \toprule
    1   &C      &\multirowcell{2}{Saída digital 1 \\a relé}\\
\cmidrule{1-2}
    2   &NA  &   \\
    \midrule \addlinespace
    3   &Dl1        & \multirowcell{2}{Entradas digitais \\ optoacopladas}\\
\cmidrule{1-2}
    4   &Dl2        &\\
    \midrule
    5   &COM 1,2    &\multirowcell{3}{\\[-2ex]1 e 2 \\ Entrada digital 3 \\ optoacoplada}\\
\cmidrule{1-2}
    6   &Dl3        & \\
\cmidrule{1-2}
    7   &COM3   & \\
    \midrule \addlinespace
    8   &Al1 +   & \multirowcell{2}{Entrada analógica 1 \\ diferencial} \\
\cmidrule{1-2}
    9   &Al1 -      & \\
    \bottomrule
\end{tabular}
\end{table}

    \end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .