# How can I prevent a line break in math inside of a table?

I have this section of TeX that describes a table

\begin{table}[h]
\begin{tabular}{|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|}
\hline
\sloppy Angle ($\theta$) deg \newline $\Delta\theta=\pm0.5$ & \sloppy Time (t) s \newline $\Delta t\nolinebreak=\pm0.11$ & \sloppy Time (t) s \newline $\Delta t\nolinebreak=\pm0.11$ & \sloppy Time (t) s \newline $\Delta t\nolinebreak=\pm0.11$ & \sloppy Time (t) s \newline $\Delta t\nolinebreak=\pm0.11$ & \sloppy Time (t) s \newline $\Delta t\nolinebreak=\pm0.11$ & \sloppy Time (t) s \newline $\Delta t=\pm0.11$ \\ \hline
0.00                         & Did not move      & Did not move      & Did not move      & Did not move      & Did not move      & Did not move      \\ \hline
15.0                         & 3.95              & 3.90              & 3.73              & 3.93              & 3.86              & 3.87              \\ \hline
30.0                         & 2.77              & 2.84              & 2.74              & 2.80              & 2.81              & 2.79              \\ \hline
45.0                         & 2.66              & 2.71              & 2.69              & 2.67              & 2.65              & 2.68              \\ \hline
60.0                         & 3.39              & 3.23              & 3.26              & 3.34              & 3.32              & 3.31              \\ \hline
75.0                         & 5.01              & 5.00              & 4.91              & 4.91              & 4.95              & 4.96              \\ \hline
90.0                         & Did not move      & Did not move      & Did not move      & Did not move      & Did not move      & Did not move      \\ \hline
\end{tabular}
\end{table}


When I build this with pdflatex on Windows 10, I get this output. What I want to be output is this: What I want is the Time (t) and s to be on different lines, and \delta t and \pm0.11 to be on the same line in the first row of the table. Also, I would like "Did not move" to be on the same line.

• Welcome to TeX. SE. if equation is longer than width of p{<width>} cell, than you cant prevent. You have three possibilities: (i) make cell width larger, (ii) use smaller font or (ii) change cell type to l or c or r. – Zarko Feb 19 '17 at 20:07
• as you see in your image the line break happens after = not before so you have the nolinebreak in the wrong place, but just preventing the break doesn't really help unless you make the expression smaller or the table wider. – David Carlisle Feb 19 '17 at 20:23
• please always post a complete (small) document so that people can reproduce the problem. For example here the problem will only arise for certain values of \linewidth so we have to guess... – David Carlisle Feb 19 '17 at 20:25
• The break means there is not enough space for keeping everything on the same line. – egreg Feb 19 '17 at 20:26

I use \mbox{} in order to avoid the line break. In addition - it has nothing to do with your question - I think that Time (t) s is not a "correct" format. I would use Time $t$ in s instead since t is a variable and should be italic (meaning in math mode). The "in" is also just a recommendation.

\documentclass[]{article}
\usepackage[showframe=true,margin=20mm]{geometry}
\usepackage{float}

\begin{document}

\begin{table}[h]
\begin{tabular}{|p{0.142\textwidth}|p{0.142\textwidth}|}
\hline
% Cell 1
Angle $\theta$ \newline
in deg  \newline
\mbox{$\Delta\theta=\pm0.5$}
&
% Cell 2
Time $t$ \newline
in s \newline
\mbox{$\Delta t=\pm0.11$}
\\ \hline
% Data
0.00 & Did not move
\end{tabular}
\end{table}

\end{document} Even if you make the cell way too small (e. g. 0.042\textwidth) then you still have no line break: Maybe have a look at Package tabularx (Error: Missing number, treated as zero.) and the links that @Werner recommends in his comment.

• @DavidCarlisle My bad - I didn't read the question thorough enough. – Dr. Manuel Kuehner Feb 19 '17 at 20:24
• @DavidCarlisle I tried again :) – Dr. Manuel Kuehner Feb 19 '17 at 20:30
• Thanks for the fix! I'll italicize the t, but I won't add "in". The format that we're using for our papers is very specific in how it wants the data formatted. – Artillect Feb 19 '17 at 20:36

I suggest to avoid repeating information; moreover spelling out “Did not move” would make the table overlong.

\documentclass{article}
\usepackage{siunitx,booktabs}

\begin{document}
\begin{table}[htp]
\centering
\newcommand{\dnm}{{DNM}}

\begin{tabular}{
@{}
S[table-format=2.0]
*{6}{S[table-format=1.2]}
@{}
}
\toprule
{Angle (deg)} & \multicolumn{6}{c@{}}{Time (s)} \\
{$\theta$} & {$t_1$} & {$t_2$} & {$t_3$} & {$t_4$} & {$t_5$} & {$\bar{t}$}\\
\cmidrule(r){1-1} \cmidrule(l){2-7}
{$\Delta\theta=\pm0.5$} & \multicolumn{6}{c@{}}{$\Delta t=\pm0.11$} \\
\midrule
0 & \dnm & \dnm & \dnm & \dnm & \dnm & \dnm \\
15 & 3.95 & 3.90 & 3.73 & 3.93 & 3.86 & 3.87 \\
30 & 2.77 & 2.84 & 2.74 & 2.80 & 2.81 & 2.79 \\
45 & 2.66 & 2.71 & 2.69 & 2.67 & 2.65 & 2.68 \\
60 & 3.39 & 3.23 & 3.26 & 3.34 & 3.32 & 3.31 \\
75 & 5.01 & 5.00 & 4.91 & 4.91 & 4.95 & 4.96 \\
90 & \dnm & \dnm & \dnm & \dnm & \dnm & \dnm \\
\bottomrule
\multicolumn{7}{@{}l@{}}{\footnotesize\dnm: Did not move}
\end{tabular}
\end{table}

\end{document} • Very cool! Nice. – Dr. Manuel Kuehner Feb 19 '17 at 20:47
• Holy crap, I love the way this looks. I'll have to check with my teacher to see if this would be a good format. – Artillect Feb 19 '17 at 20:53
• What do the parameters that follow \begin{tabular} do? – Artillect Feb 20 '17 at 0:18
• @Artillect S[table-format=1.2] means a column with aligned numbers with one digit in the integral part and two in the fractional part. – egreg Feb 20 '17 at 0:25
• @egreg If I wanted to use this same formatting for a 2 column table with text only, what would I need to change? – Artillect Feb 20 '17 at 0:39

Since the page layout of your document is not known, the following solution is based on guessing, that is close to what is obtained by us of \usepackage[showframe]{geometry} package.

With packages siunitx (for units and column formatting), tabularx (for simple formatting of table with equal width columns) and makecell for column headers, I obtain the following table: \documentclass{article}
\usepackage[showframe]{geometry}% <-- this solve problem with breaking equation into two line
\usepackage{makecell,tabularx}
\newcommand\mcx{\multicolumn{1}{>{\centering\arraybackslash}X|}{#1}}
\usepackage{siunitx}

\begin{document}
\begin{table}
\begin{tabularx}{\linewidth}{|S[table-format=2.2]|
*{6}{S[table-format=1.2]|}
}
\hline
{\thead{Angle ($\theta$)\\ $\Delta\theta=\SI{\pm0.5}{\degree}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&  {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}  \\
\hline
0.00    & \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}    \\ \hline
15.0    & 3.95  & 3.90  & 3.73  & 3.93  & 3.86  & 3.87                  \\ \hline
30.0    & 2.77  & 2.84  & 2.74  & 2.80  & 2.81  & 2.79                  \\ \hline
45.0    & 2.66  & 2.71  & 2.69  & 2.67  & 2.65  & 2.68                  \\ \hline
60.0    & 3.39  & 3.23  & 3.26  & 3.34  & 3.32  & 3.31                  \\ \hline
75.0    & 5.01  & 5.00  & 4.91  & 4.91  & 4.95  & 4.96                  \\ \hline
90.0    & \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}    \\ \hline
\end{tabularx}
\end{table}
\end{document}


Note: default font size in \thead is \footnotesize.

Edit: Reducing page margins to 25mm and \tabcolsep from default 6pt to 3pt, andd increase thead font size to small and \arraystretch to 1.2, the table become: \documentclass{article}
\usepackage[showframe,
margin=25mm]{geometry}% <-- this solve problem with breaking equation into two line
\usepackage{makecell,tabularx}
\newcommand\mcx{\multicolumn{1}{>{\centering}X|}{#1}}
\usepackage{siunitx}

\begin{document}
\begin{table}
\setlength\tabcolsep{3pt}
\renewcommand\arraystretch{1.2}
\begin{tabularx}{\linewidth}{|S[table-format=2.2]|
*{6}{S[table-format=1.2]|}
}
\hline
{\thead{Angle ($\theta$)\\ $\Delta\theta=\SI{\pm0.5}{\degree}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&  {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}
&   {\thead{Time ($t$)\\ $\Delta t=\SI{\pm0.11}{s}$}}  \\
\hline
0.00    & \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}    \\ \hline
15.0    & 3.95  & 3.90  & 3.73  & 3.93  & 3.86  & 3.87                  \\ \hline
30.0    & 2.77  & 2.84  & 2.74  & 2.80  & 2.81  & 2.79                  \\ \hline
45.0    & 2.66  & 2.71  & 2.69  & 2.67  & 2.65  & 2.68                  \\ \hline
60.0    & 3.39  & 3.23  & 3.26  & 3.34  & 3.32  & 3.31                  \\ \hline
75.0    & 5.01  & 5.00  & 4.91  & 4.91  & 4.95  & 4.96                  \\ \hline
90.0    & \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}
& \mcx{Did not move}    \\ \hline
\end{tabularx}
\end{table}
\end{document}


Note (2): when columns width is enough large then equation is not broken and prevent its breaking with with \mbox{$<equation>$} is surplus. This fix can cause new problem in table: if cell is narrower then column width -- equation spill-out on the right side as is shown in Dr. Manuel Kuehner answer. my conclusion: fix for your table is make columns' width larger ...

• the space between the two lines of "did not move" is excessive. this would be better treated as a paragraph rather than as a two-line table entry. – barbara beeton Feb 20 '17 at 1:54
• yes, this degrade table looks. With further increase table width (with smaller page margins) the all texts are fitted in one line. See edit of my answer. – Zarko Feb 20 '17 at 3:49

Still not pretty but \documentclass{article}

\begin{document}
\begin{table}[htp]
\begin{tabular}{|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|p{0.142\linewidth}|}
\hline
\centering\small Angle~($\theta$)\,deg \\ $\Delta\theta=\pm0.5$ &
\centering\small Time (t)\,s \\ $\Delta t=\pm0.11$ &
\centering\small Time (t)\,s \\ $\Delta t=\pm0.11$ &
\centering\small Time (t)\,s \\ $\Delta t=\pm0.11$ &
\centering\small Time (t)\,s \\ $\Delta t=\pm0.11$ &
\centering\small Time (t)\,s \\ $\Delta t=\pm0.11$ &
\centering\small Time (t)\,s \\ $\Delta t=\pm0.11$ \tabularnewline
\hline
0.00                         &
\centering Did not move      &
\centering Did not move      &
\centering Did not move      &
\centering Did not move      &
\centering Did not move      &
\centering Did not move      \tabularnewline
\hline
15.0                         & 3.95              & 3.90              & 3.73              & 3.93              & 3.86              & 3.87              \\ \hline
30.0                         & 2.77              & 2.84              & 2.74              & 2.80              & 2.81              & 2.79              \\ \hline
45.0                         & 2.66              & 2.71              & 2.69              & 2.67              & 2.65              & 2.68              \\ \hline
60.0                         & 3.39              & 3.23              & 3.26              & 3.34              & 3.32              & 3.31              \\ \hline
75.0                         & 5.01              & 5.00              & 4.91              & 4.91              & 4.95              & 4.96              \\ \hline
90.0                         & \centering Did not move      & \centering Did not move      & \centering Did not move      & \centering Did not move      & \centering Did not move      & \centering Did not move      \tabularnewline
\hline
\end{tabular}
\end{table}
\end{document}

• \centering makes it indeed prettier . – Dr. Manuel Kuehner Feb 19 '17 at 20:45
• @Dr.ManuelKuehner not much:) – David Carlisle Feb 19 '17 at 20:56