Span over multiple lines with tabularx

Span over multiple lines with tabularx

I am trying to have a table with tabularx for a document where the text is supposed to be filled in later on manually in writing. So, of course, I want the row where the input is supposed to span over multiple lines.

While I do know that with \\ I am able to get to the next line, the border I want this table to have is not produced to the right of this row.

Here's the sample code:

\begin{table}[htb]
\begin{tabularx}{\textwidth}{|l|X|}
\hline
Foo & bar\\ \hline
Multiline     \\ \\ \\ &  Span this row for multiple lines for writing input\\ \hline
\end{tabularx}
\end{table}

답변1

To obtain the additional vertical bar, at the right-hand edge of the tabular material, you need to change

Multiline     \\ \\ \\ &  Span this ...

to

Multiline     & \\ & \\ & \\ &  Span this ...

A full MWE (minimum working example)

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}[htb]
\begin{tabularx}{\textwidth}{|l|X|}
  \hline
  Foo & bar\\ 
  \hline
  Multiline & \\    % no text in second column
    & \\ & \\       % no text in either column, for 2 rows
    & Span this row for multiple lines for writing input\\
  \hline
\end{tabularx}
\end{table}
\end{document}

답변2

A variant, to save counting the number of \\s, in case one needs many:

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularx}

\begin{document}

\begin{table}[htb]
\setlength{\extrarowheight}{2pt}
\begin{tabularx}{\textwidth}{|l|X|}
  \hline
  Foo & bar\\
  \hline
  Multiline & \\ % no text in second column
   & \rule{0pt}{10\baselineskip}\\
    & Span this row for multiple lines for writing input\\
  \hline
\end{tabularx}
\end{table}

\end{document} 

enter image description here

관련 정보