Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like the sentence "Why get someone who only pretends to be a doctor when you could get a real one?" to fit into this 430pt table. But the sentence doesn't break after "could" and keeps running out of line. Shouldn't long sentences automatically break into paragraph in tabularx? How can I fix it? enter image description here

\documentclass[11pt]{book}

\usepackage{tabularx,pbox}

\begin{document}

\begin{table}
\begin{tabularx}{430pt}{|c|X|}
\hline
\textbf{Paragraph \#} & \textbf{Description:} \\
\hline
1 & \pbox{20cm}{\emph{Rhetorical questions/Introduction} \\ 
    Why get someone who only \emph{pretends} to be a doctor when you 
    could get a real one? \\ \emph{Relate to audience} \\ Some more sentence
    here.} \\ 

\end{tabularx}
\end{table}
\end{document}

I could insert \\ after "could" to manually break the line. But that would totally defeat the purpose.

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

You need no \pbox:

\documentclass[11pt]{book}

\usepackage{tabularx}

\begin{document}

\begin{table}
\centering

\renewcommand{\tabularxcolumn}{m} % we want center vertical alignment

\begin{tabularx}{\textwidth}{|c|>{\raggedright}X|}
\hline
\textbf{Paragraph \#} & \textbf{Description:} \tabularnewline
\hline
1 & \emph{Rhetorical questions/Introduction} \\
    Why get someone who only \emph{pretends} to be a doctor when you
    could get a real one? \\
    \emph{Relate to audience} \\
    Some more sentence here. \tabularnewline
\hline
\end{tabularx}
\end{table}
\end{document}

enter image description here

However, the number all alone in that big space is rather ugly.

Here's another possibility, without vertical rules.

\documentclass[11pt]{book}

\usepackage{tabularx,booktabs}

\begin{document}

\begin{table}
\centering
\begin{tabularx}{\textwidth}{c>{\raggedright}X}
\toprule
\textbf{Par.\ \#} & \textbf{Description:} \tabularnewline
\midrule
1 & \emph{Rhetorical questions/Introduction} \\
    Why get someone who only \emph{pretends} to be a doctor when you
    could get a real one? \\
    \emph{Relate to audience} \\
    Some more sentence here. \tabularnewline
\midrule
2 & \emph{Rhetorical questions/Introduction} \\
    Why get someone who only \emph{pretends} to be a doctor when you
    could get a real one? \\
    \emph{Relate to audience} \\
    Some more sentence here. \tabularnewline
\bottomrule
\end{tabularx}
\end{table}
\end{document}

enter image description here

share|improve this answer
    
Does \tabularnewline mean to introduce new row? I think it's clearer than `\`. Your table looks pretty btw. But I'm wondering how come the vertical rules don't connect at the corners? –  pineapple Jun 2 at 9:02
    
@pineapple If you use \toprule and friends, you mustn't use vertical rules. That's the principle booktabs is based on. –  egreg Jun 2 at 9:08
add comment

The problem arises because \pbox{20cm}{...} is quite a bit wider than what's assigned to the column of type X. You could either calculate explicitly how wide this column really is (and adjust the first argument of \pbox) or you do something as follows:

\documentclass[11pt]{book}
\usepackage{tabularx,pbox}
\begin{document}
\begin{table}
\begin{tabularx}{430pt}{|c|X|}
\hline
\textbf{Paragraph \#} & \textbf{Description:} \\
\hline
1 & \emph{Rhetorical questions/Introduction} \\
  & Why get someone who only \emph{pretends} to be a doctor when you  get a real one? \\ 
  & \emph{Relate to audience} \\ 
  & Some more sentences here. \\
\hline
\end{tabularx}
\end{table}
\end{document}
share|improve this answer
1  
Since X is a special p{...} coulnd't you just get away with using \newline instead of those & + `\` combos? Thus getting the same one row structure as the OP. –  daleif Jun 2 at 6:58
    
@daleif - I guess the optimal adjustment depends in part on where the OP wants the 1 in first column placed: on the first row of the material on the right, or centered vertically with respect to the material on the right. –  Mico Jun 2 at 7:30
    
@Mico: I changed \pbox to 11.5cm, and it worked perfectly. Those & also gave the same result, but words will have em dash at the end of the line. –  pineapple Jun 2 at 7:36
    
@pineapple - Glad things are working for you now. –  Mico Jun 2 at 7:40
    
@Mico: Thank you! I like \pbox because it centers the 1, like you said, vertically w.r.t the description. –  pineapple Jun 2 at 7:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.