我有以下长表,我希望第三列自动换行,而不是强制换行。有什么办法吗?
这是长表的样子,我在这里强制换行 https://i.stack.imgur.com/9BFeY.jpg“长桌长什么样”
下面代码中的表格如下所示: https://i.stack.imgur.com/nklKY.jpg“来自代码示例”
\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}
答案1
正如第一条评论所暗示的那样,使用p
适当宽度的列是防止手动换行的解决方案。
我不知道你为什么要嵌套表格。你可能在寻找m
列。我在其实现中对表格进行了相当大的更改,并通过反复试验调整了宽度。
\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}