0

I have the following longtable where i want the third column to do an auto-linebreak, instead of me having to do it forced. Is there any way to do this?

This is a image of how the long table looks, where i did forced linebreaks https://i.stack.imgur.com/9BFeY.jpg "how the long table looks"

This is how the table in the code below looks like: https://i.stack.imgur.com/nklKY.jpg "from code example"

\begin{center}
\renewcommand{\tabcolsep}{3pt}
\begin{longtable}{|c|c|c|c|c|c|}
\caption{\textbf{Veterinarian and pet shop interview analysis}}\\
\hline
\textbf{Theme} & \textbf{Sub theme} & \textbf{Raw data} & \textbf{Code} & \textbf{Findings} & \textbf{+/-} \\
\hline
\endfirsthead
\multicolumn{6}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{Theme} & \textbf{Sub theme} & \textbf{Raw data} & \textbf{Code} & \textbf{Findings} & \textbf{+/-} \\
\hline
\endhead
\hline \multicolumn{6}{r}{\textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
\begin{tabular}[c]{@{}l@{}}1. Increase\\ of overwe-\\ ight dogs \\ in Denmark\end{tabular} & \begin{tabular}[c]{@{}l@{}}Measurement\\ method\end{tabular} & \textit{\begin{tabular}[c]{@{}l@{}}Vet: Many sources tell that it is increasing and this is somewhat based on the veterinarian's experiences and impressions.\\ PS: We often see in the shop that many of the dogs who enter are overweight. Actually it is so big a problem that the shop i am in have chosen to put up a dog weight in the shop, so that the customers can weight their dog when they come in here.\end{tabular}} & VP1.1 & \begin{tabular}[c]{@{}l@{}}1. Increase \\ of overweight \\ dogs in \\ Denmark is \\ based on \\ estimates\end{tabular} & \begin{tabular}[c]{@{}l@{}}+\\ +\end{tabular} \\ \hline
\end{longtable}
\end{center}
7
  • p{<width>} as you have at the top will enable automatic line-breaking. It isn't clear which bit you are referring to by the 'third column' given that you seem to have multiple tables there. What is the point of the nested tabulars with only one column?
    – cfr
    Dec 11, 2015 at 23:54
  • If you post a complete example people can copy-paste-compile you are more likely to get effective help. What do the +s do? Using H for longtable is pointless. It won't float anyway, so you don't need to stop it.
    – cfr
    Dec 11, 2015 at 23:54
  • What is you paper size? Your column widths don't seem to fit usual sizes.
    – Bernard
    Dec 12, 2015 at 0:36
  • Sorry, the width of the column was just something i tried to force the line breaks, but the text just went out of the cell then. Edited the code now. The column im talking about is the third one after the line that says "\endlastfoot". Everything before that is just to give the long table af "headline" row on all pages.
    – Kenneth J
    Dec 12, 2015 at 9:03
  • 1
    Kenneth, the example cannot compile. The documentclass, the packages, the document environment are missing.
    – Johannes_B
    Dec 12, 2015 at 9:17

1 Answer 1

1

As already hinted in the very first comment, using p columns with an appropriate width is the solution to prevent manual line breaking.

I don't know why you are nesting tabulars. You might be looking for m columns. I changed the table in its implementation quite a bit and adjusted the width by trial and error.

kennethLongtable

\documentclass{article}
\usepackage[english]{babel}
\usepackage{longtable}
\usepackage{array}
\usepackage{geometry}
\geometry{a4paper,showframe,textheight=10cm}
\newcolumntype{K}{>{\raggedright\arraybackslash\hspace{0pt}}m}
\newcommand{\tabhead}[2]{\multicolumn{1}{#1}{\bfseries#2}}
\newcommand{\positive}{$+$ }
\usepackage{amssymb}
%\renewcommand{\positive}{\checkmark\space}
\newcommand{\negative}{$-$ }
%\renewcommand{\negative}{$\times$ }
\begin{document}
\begin{longtable}{|K{.12\linewidth}|K{.13\linewidth}|>{\itshape}K{.34\linewidth}|K{.07\linewidth}|K{.11\linewidth}|>{\centering\arraybackslash}m{.03\linewidth}|}
        \caption{\textbf{Veterinarian and pet shop interview analysis}}\\
        \hline
        \tabhead{|c|}{Theme} & \tabhead{c|}{Sub theme} & \tabhead{c|}{Raw data} &
        \tabhead{c|}{Code} & \tabhead{c|}{Findings} & \tabhead{c|}{+/-} \\
        \hline
        \endfirsthead
        \multicolumn{6}{c}%
        {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
        \hline
        \tabhead{|c|}{Theme} & \tabhead{c|}{Sub theme} & \tabhead{c|}{Raw data} &
        \tabhead{c|}{Code} & \tabhead{c|}{Findings} & \tabhead{c|}{+/-} \\
        \hline
        \endhead
        \hline \multicolumn{6}{r}{\textit{Continued on next page}} \\
        \endfoot
        \hline
        \endlastfoot
        1. Increase of overweight dogs  in Denmark & Measurement method &
        Vet: Many sources tell that it is increasing and this is somewhat
        based on the veterinarian's experiences and impressions. \par PS: We
        often see in the shop that many of the dogs who enter are
        overweight. Actually it is so big a problem that the shop i am in
        have chosen to put up a dog weight in the shop, so that the
        customers can weight their dog when they come in here. &
        VP1.1 & 1.~Increase  of overweight  dogs in  Denmark is  based on
        estimates & \positive \positive \\ \hline
        1. Increase of overweight dogs  in Denmark & Measurement method &
        Vet: Many sources tell that it is increasing and this is somewhat
        based on the veterinarian's experiences and impressions. \par PS: We
        often see in the shop that many of the dogs who enter are
        overweight. Actually it is so big a problem that the shop i am in
        have chosen to put up a dog weight in the shop, so that the
        customers can weight their dog when they come in here. &
        VP1.1 & 1.~Increase  of overweight  dogs in  Denmark is  based on
        estimates & \positive \negative  \\ \hline
    \end{longtable}
\end{document}
2
  • Am i doing something wrong or is there something wrong with your code? This puts my entire document in cells. Sorry, i am rather new to latex.
    – Kenneth J
    Dec 12, 2015 at 11:18
  • Play around to find out what causes the behaviour. I can only assume, that you don't know what option showframe is doing.
    – Johannes_B
    Dec 12, 2015 at 11:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .