[Tex/LaTex] One cell with multiple lines

tables

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.

Best Answer

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

Related Question