Text Formattingsetspace | Line Spacing in Tables messed up

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ougka
Posts: 43
Joined: Wed Jan 19, 2011 5:02 pm

setspace | Line Spacing in Tables messed up

Post by ougka »

Hello,

I want to have 1.4 line spacing. I tried to use the setspace package but it messes up with my tables as well to the point they become small and unreadable.

I've searched this forum and tried to find some documentation for the package to see if there is a parameter that I should use when I import it, but I've found nothing.

How can I use it without it messing about with my tables?

Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

setspace | Line Spacing in Tables messed up

Post by localghost »

Get used to always showing what you are doing to avoid guesswork.


Thorsten
ougka
Posts: 43
Joined: Wed Jan 19, 2011 5:02 pm

Re: setspace | Line Spacing in Tables messed up

Post by ougka »

Hi Thorsten,

I usually do provide an example of what I am doing, when I am doing something more intricate, but here it is just a simple questions isn't it?

I want to know if there is any parameter in the setspace package that does NOT enforce the line spacing stretch to tables.

Because of the way my project is structured it is going to take me a lot of time to produce something that you can replicate. This is not out of disrespect to the reader, but because I thought the question was simple. If you still want a minimal example, I can try to create one later.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

setspace | Line Spacing in Tables messed up

Post by localghost »

ougka wrote:[…] I usually do provide an example of what I am doing, when I am doing something more intricate, but here it is just a simple questions isn't it? […]
A seemingly simple question can turn out to be more complicated than you thought. So a small example is always helpful. And nobody knows how you really set up the line spacing. The recommended way is to do this is by package options or -- in case of custom line spacing -- by the \setstretch command which is provided by the package.
ougka wrote:[…] I want to know if there is any parameter in the setspace package that does NOT enforce the line spacing stretch to tables. […]
And you already did read the setspace manual and searched for hints? Note that you have to look into the package file (*.sty) itself for the instructions. Usually the package is loaded with an option like onehalfspacing and things like tables will be untouched. There is also an environment called singlespace where you might switch back to single line spacing if you wrap your tables with it.
ougka wrote:[…] Because of the way my project is structured it is going to take me a lot of time to produce something that you can replicate. […]
A simple document with an equally simple table should do.
ougka wrote:[…] This is not out of disrespect to the reader, but because I thought the question was simple. […]
As I already mentioned, questions can be more complicated when you take a closer look.
ougka wrote:[…] If you still want a minimal example, I can try to create one later.
Please do so. Very appreciated.


Addendum:
The below counterexample doesn't cause any problems.

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[tableposition=top]{caption}
\usepackage{setspace}
\usepackage{lipsum}

\setstretch{1.4}

\begin{document}
  \lipsum[1]
  
  \begin{table}[!ht]
    \caption{Table caption}
    \centering
    \begin{tabular}{cc}\hline
      Table Head & Table Head \\ \hline
      Some Values & Some Values \\
      Some Values & Some Values \\
      Some Values & Some Values \\ \hline
    \end{tabular}
  \end{table}
  
  \lipsum[2]
\end{document}
ougka
Posts: 43
Joined: Wed Jan 19, 2011 5:02 pm

setspace | Line Spacing in Tables messed up

Post by ougka »

Hello localghost,

Thanks for your reply and your addendum and sorry for not being able to get back to you earlier. Indeed your MWE doesn't reproduce the error. But mine does :(

So here is the code with the setspace package and setstretch{1.4}

Code: Select all

    \documentclass[12pt,a4paper]{article}
    \usepackage[T1]{fontenc}
    \usepackage{setspace}
    \usepackage{lipsum}

    \usepackage{rotating}
    \usepackage{multirow}

    \setstretch{1.4}

    \begin{document}
      \lipsum[1]

          
      \begin{table}[!thb]
   \centering{
   \begin{tabular}{|c |l | l |c | c | c | c |}
\hline
       \multicolumn{3}{|c|}{\textbf{Host Mobility}} & \textbf{R1} & \textbf{R2} & \textbf{R4} & \textbf{R5} \\ %       
       \hline
			 \multirow{9}{*}{\begin{sideways}\textbf{TTLS}\end{sideways}}&
             \multirow{4}{*}{\begin{sideways}\textbf{Test 1}\end{sideways}}
             &   CUI on (sec)  & 0.2151   & 0.1903   & 0.0091  & 0.2034   \\ \cline{3-7}
			 & & CUI off (sec)   & 0.2105   & 0.1811   & 0.0082  & 0.1997   \\ \cline{3-7}
			 & & Overhead (ms)    & 4.6      & 9.2      & 0.9    & 3.7     \\ \cline{3-7}
			 & & Overhead (\%)    & 2.2      & 5.1      & 11.0    & 1.9      \\ \cline{2-7}
             \vspace{-0.70cm} \\ \cline{2-7}
             & \multirow{4}{*}{\begin{sideways}\textbf{Test 2}\end{sideways}}
             &   CUI on (sec)  & 0.0952   & 0.0391   & 0.0081  & 0.0490  \\ \cline{3-7}
			 & & CUI off (sec)   & 0.0875   & 0.0370   & 0.0074  & 0.0416  \\ \cline{3-7}
			 & & Overhead (ms)    & 7.7      & 2.1      & 0.7     & 7.4     \\ \cline{3-7}
			 & & Overhead (\%)    & 8.8      & 5.7      & 9.5    & 17.8     \\
\hline
\hline
			 \multirow{8}{*}{\begin{sideways}\textbf{TLS}\end{sideways}}&
             \multirow{4}{*}{\begin{sideways}\textbf{Test 3}\end{sideways}}
             &   CUI on (sec)   & 0.2061  & 0.1894   & 0.0093  & 0.2011  \\ \cline{3-7}
			 & & CUI off (sec)   & 0.1993   & 0.1856   & 0.0085  & 0.1953  \\ \cline{3-7}
			 & & Overhead (ms)    & 6.8      & 3.8      & 0.8     & 5.8     \\ \cline{3-7}
			 & & Overhead (\%)    & 3.4      & 2.0      & 9.4    & 3.0     \\ \cline{2-7}
             \vspace{-0.70cm} \\ \cline{2-7}
             & \multirow{4}{*}{\begin{sideways}\textbf{Test 4}\end{sideways}}
             &   CUI on (sec)  & 0.0511   & 0.0402   & 0.0101  & 0.0440  \\ \cline{3-7}
			 & & CUI off (sec)   & 0.0465   & 0.0343   & 0.0094  & 0.0391  \\ \cline{3-7}
			 & & Overhead (ms)    & 4.6      & 5.9      & 0.7     & 4.9     \\ \cline{3-7}
			 & & Overhead (\%)    & 9.9      & 17.2      & 7.4    & 12.5     \\ \hline
		\end{tabular}
	\caption{Teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest}
	\label{test}
}
\end{table}
      \lipsum[2]

    \end{document} 
Which produces the following table :
table-bad.png
table-bad.png (50.55 KiB) Viewed 17326 times
And here is the same code but without setspace and with baselinstretch{1.4} :

Code: Select all

    \documentclass[12pt,a4paper]{article}
    \usepackage[T1]{fontenc}
   % \usepackage{setspace}
    \usepackage{lipsum}

    \usepackage{rotating}
    \usepackage{multirow}

    %\setstretch{1.4}

    \renewcommand{\baselinestretch}{1.4}

    \begin{document}
      \lipsum[1]

     
      
      \begin{table}[!thb]
   \centering{
   \begin{tabular}{|c |l | l |c | c | c | c |}
\hline
       \multicolumn{3}{|c|}{\textbf{Host Mobility}} & \textbf{R1} & \textbf{R2} & \textbf{R4} & \textbf{R5} \\ %       
       \hline
			 \multirow{9}{*}{\begin{sideways}\textbf{TTLS}\end{sideways}}&
             \multirow{4}{*}{\begin{sideways}\textbf{Test 1}\end{sideways}}
             &   CUI on (sec)  & 0.2151   & 0.1903   & 0.0091  & 0.2034   \\ \cline{3-7}
			 & & CUI off (sec)   & 0.2105   & 0.1811   & 0.0082  & 0.1997   \\ \cline{3-7}
			 & & Overhead (ms)    & 4.6      & 9.2      & 0.9    & 3.7     \\ \cline{3-7}
			 & & Overhead (\%)    & 2.2      & 5.1      & 11.0    & 1.9      \\ \cline{2-7}
             \vspace{-0.70cm} \\ \cline{2-7}
             & \multirow{4}{*}{\begin{sideways}\textbf{Test 2}\end{sideways}}
             &   CUI on (sec)  & 0.0952   & 0.0391   & 0.0081  & 0.0490  \\ \cline{3-7}
			 & & CUI off (sec)   & 0.0875   & 0.0370   & 0.0074  & 0.0416  \\ \cline{3-7}
			 & & Overhead (ms)    & 7.7      & 2.1      & 0.7     & 7.4     \\ \cline{3-7}
			 & & Overhead (\%)    & 8.8      & 5.7      & 9.5    & 17.8     \\
\hline
\hline
			 \multirow{8}{*}{\begin{sideways}\textbf{TLS}\end{sideways}}&
             \multirow{4}{*}{\begin{sideways}\textbf{Test 3}\end{sideways}}
             &   CUI on (sec)   & 0.2061  & 0.1894   & 0.0093  & 0.2011  \\ \cline{3-7}
			 & & CUI off (sec)   & 0.1993   & 0.1856   & 0.0085  & 0.1953  \\ \cline{3-7}
			 & & Overhead (ms)    & 6.8      & 3.8      & 0.8     & 5.8     \\ \cline{3-7}
			 & & Overhead (\%)    & 3.4      & 2.0      & 9.4    & 3.0     \\ \cline{2-7}
             \vspace{-0.70cm} \\ \cline{2-7}
             & \multirow{4}{*}{\begin{sideways}\textbf{Test 4}\end{sideways}}
             &   CUI on (sec)  & 0.0511   & 0.0402   & 0.0101  & 0.0440  \\ \cline{3-7}
			 & & CUI off (sec)   & 0.0465   & 0.0343   & 0.0094  & 0.0391  \\ \cline{3-7}
			 & & Overhead (ms)    & 4.6      & 5.9      & 0.7     & 4.9     \\ \cline{3-7}
			 & & Overhead (\%)    & 9.9      & 17.2      & 7.4    & 12.5     \\ \hline
		\end{tabular}
	\caption{Teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest}
	\label{test}
}
\end{table}


      \lipsum[2]

    \end{document} 
that does not produce the problem. As a matter of fact here is the table :
table-good.png
table-good.png (53.94 KiB) Viewed 17326 times
I hope this helps, any ideas?
Last edited by localghost on Sun Sep 02, 2012 11:07 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

setspace | Line Spacing in Tables messed up

Post by localghost »

Let's hope that you now see why a proper minimal example is always essential to reproduce a problem. If you wouldn't have provided the example, nobody would be able to fix it.

The code of your table is a bit problematic at the places where you try to produce a double \cline and mess around a bit with negative vertical space by \vspace. The below code tries to repair this.

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[tableposition=top]{caption}
\usepackage{setspace}
\usepackage{rotating}
\usepackage{multirow}
\usepackage{lipsum}

\setstretch{1.4}
\renewcommand{\arraystretch}{1.2}  % increase row head in arrays or tables

\begin{document}
  \lipsum[1]

  \begin{table}[!htb]
    \caption{Table caption}
    \label{tab:dummy}
    \centering
    \begin{tabular}{|c|l|l|c|c|c|c|}\hline
      \multicolumn{3}{|c|}{\textbf{Host Mobility}} & \textbf{R1} & \textbf{R2} & \textbf{R4} & \textbf{R5} \\ \hline
      \multirow{8}{*}{\begin{sideways}\textbf{TTLS}\end{sideways}} &
      \multirow{4}{*}{\begin{sideways}\textbf{Test 1}\end{sideways}}
        & CUI on (sec)  & 0.2151 & 0.1903 & 0.0091 & 0.2034 \\ \cline{3-7}
      & & CUI off (sec) & 0.2105 & 0.1811 & 0.0082 & 0.1997 \\ \cline{3-7}
      & & Overhead (ms) & 4.6    & 9.2    & 0.9    & 3.7    \\ \cline{3-7}
      & & Overhead (\%) & 2.2    & 5.1    & 11.0   & 1.9    \\ \cline{2-7}\cline{2-7}
      & \multirow{4}{*}{\begin{sideways}\textbf{Test 2}\end{sideways}}
        & CUI on (sec) & 0.0952 & 0.0391   & 0.0081  & 0.0490  \\ \cline{3-7}
      & & CUI off (sec)   & 0.0875   & 0.0370   & 0.0074  & 0.0416  \\ \cline{3-7}
      & & Overhead (ms)    & 7.7      & 2.1      & 0.7     & 7.4     \\ \cline{3-7}
      & & Overhead (\%)    & 8.8      & 5.7      & 9.5    & 17.8     \\ \hline\hline
      \multirow{8}{*}{\begin{sideways}\textbf{TLS}\end{sideways}}&
      \multirow{4}{*}{\begin{sideways}\textbf{Test 3}\end{sideways}}
        & CUI on (sec)  & 0.2061 & 0.1894 & 0.0093 & 0.2011  \\ \cline{3-7}
      & & CUI off (sec) & 0.1993 & 0.1856 & 0.0085 & 0.1953  \\ \cline{3-7}
      & & Overhead (ms) & 6.8    & 3.8    & 0.8    & 5.8     \\ \cline{3-7}
      & & Overhead (\%) & 3.4    & 2.0    & 9.4    & 3.0     \\ \cline{2-7}\cline{2-7}
      & \multirow{4}{*}{\begin{sideways}\textbf{Test 4}\end{sideways}}
      & CUI on (sec)    & 0.0511 & 0.0402 & 0.0101 & 0.0440  \\ \cline{3-7}
      & & CUI off (sec) & 0.0465 & 0.0343 & 0.0094 & 0.0391  \\ \cline{3-7}
      & & Overhead (ms) & 4.6    & 5.9    & 0.7    & 4.9     \\ \cline{3-7}
      & & Overhead (\%) & 9.9    & 17.2   & 7.4    & 12.5    \\ \hline
    \end{tabular}
  \end{table}

  \lipsum[2]
\end{document}
By the way, it is often recommended to drop vertical lines in tables completely to improve readability. The booktabs package shows how to produce good looking and readable tables.
ougka
Posts: 43
Joined: Wed Jan 19, 2011 5:02 pm

Re: setspace | Line Spacing in Tables messed up

Post by ougka »

Thank you so so much localghost! (sorry for my late reply)

The \arraystretch and the removal of the vspaces did the trick :D

ps. I totally do see the viewpoint of the MWE, it is just that in some question I do believe there is a quick answer without an MWE. Anyway, thanks a lot!
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

setspace | Line Spacing in Tables messed up

Post by cgnieder »

ougka wrote:I totally do see the viewpoint of the MWE, it is just that in some question I do believe there is a quick answer without an MWE. Anyway, thanks a lot!
Well, some questions can be answered without an MWE. But if one is having trouble with some issue and can not exactly pinpoint what it is (down to code level) then one most likely is not in the position to know if an MWE is needed or not. So it's better to provide one. (One might also find the source of the troubles oneself during the process of creating one!) Besides: even if it is not needed potential helpers are faster and more willing to provide help if an MWE is given… So it's best simply to provide an MWE every time.

Regards
site moderator & package author
Post Reply