如何解决longtable latex中的文本换行问题?

如何解决longtable latex中的文本换行问题?

在此处输入图片描述

    \documentclass[12pt]{article}
    \usepackage{longtable}
    \usepackage[landscape]{geometry}
    \usepackage{pdflscape}

    \begin{document}

    \begin{center}

    \begin{longtable}{|p{3cm}|p{6cm}|p{6cm}|p{6cm}|}
    \caption{A simple longtable example}\\
    \hline
    \textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
    \hline
    \endfirsthead
    \multicolumn{4}{c}%
    {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
    \hline
    \textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
    \hline
    \endhead
    \hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot
    \begin{itemize} \item TEAM/ UNIT/ Organisation  \end{itemize}  
   & \begin{itemize}
    \item To maintain staff passion to maintain data provider trust in 
    releasing data because the data providers could get feedbacks during 
    verifications.
   \end{itemize}
   & \begin{enumerate}\item To explore the Idea of a merger* with  existing 
   expertise/resources in MOH to upgrade the hardcopy reports into 
   electronic version ie bona fide Performance Dashboard possibly using the 
   system that has been developed. 
   \item Use the prototype Performance Dashboard to help clients “see” its 
   potentials to help them in their work, so that they can come up with what 
   matters to them (direction) that eventually helps MHPU/PIK to revise 
   their strategic plans/performance metrics
   \end{enumerate}
  & \begin{itemize} \item To maintain staff passion to maintain data 
   provider trust in releasing data because the data providers could get 
   feedbacks during verifications. 
  \end{itemize}  \\
  \hline
  Team/ Unit/ Organisation & To maintain staff passion to maintain data 
  provider trust in releasing data because the data providers could get 
  feedbacks during verifications.   

   & 1.To maintain staff passion to maintain data provider trust in 
   releasing data because the data providers could get feedbacks during 
   verifications.

   2.To explore the Idea of a merger* with  existing expertise/resources to 
   upgrade the hardcopy reports into electronic version ie  bona fide 
   Performance Dashboard possibly using the system that has been developed 
   by 

   3. Use the prototype Performance Dashboard to help clients “see” its 
   potentials to help them in their work, so that they can come up with
   what matters to them (direction) that eventually helps MHPU/PIK to revise 
   their strategic plans/performance metrics.       

   4. To explore the Idea of a merger* with  existing expertise/resources in    
   MOH to upgrade the hardcopy reports into electronic version ie bona fide 
   Performance Dashboard possibly using the system that has been developed. 

   5. To explore the Idea of a merger* with  existing expertise/resources 
   to upgrade the hardcopy reports into electronic version ie bona fide 
   Performance Dashboard possibly using the system that has been developed.

    & To maintain staff passion to maintain data provider trust in releasing 
    data because the data providers could get feedbacks during 
    verifications. \\

    11111111111 & 22222222222222222222222 & 3333333333333333 & 444444 \\ 
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 
     1 & 2 & 3 & 4 

    \end{longtable}

    \end{center}

   \end{document}

答案1

借助于enumitem相对于文本宽度计算的列宽,您可以实现以下目标:

在此处输入图片描述

使用不同的列宽可以节省很多空间:

在此处输入图片描述

 \documentclass[12pt]{article}
 \usepackage{longtable}
 \usepackage[landscape]{geometry}
 \usepackage{ragged2e}
 \usepackage{calc,array}

\usepackage{enumitem}
\newlist{tabitem}{itemize}{1}
\newlist{tabenum}{enumerate}{1}

\setlist[tabitem]{nosep,
                  topsep= 0pt,
                  partopsep=0pt,
                  leftmargin= *,
                  label=\textbullet,
                  before=\vspace{-0.6\baselineskip},
                  after=\vspace{-\baselineskip}
                  } 
 \setlist[tabenum]{nosep,
                  topsep= 0pt,
                  partopsep=0pt,
                  leftmargin= *,
                  label=\arabic*.,
                  before=\vspace{-0.6\baselineskip},
                  after=\vspace{-\baselineskip}
                  } 

 \begin{document}
 {\RaggedRight
 \begin{longtable}{|p{0.145\textwidth-2\tabcolsep-2\arrayrulewidth}|p{0.285\textwidth-2\tabcolsep-\arrayrulewidth}|p{0.285\textwidth-2\tabcolsep-\arrayrulewidth}|p{0.285\textwidth-2\tabcolsep-\arrayrulewidth}|}
 \caption{A simple longtable example}\\
 \hline
 \textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
 \hline
 \endfirsthead
 \multicolumn{4}{c}%
 {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
 \hline
 \textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
 \hline
 \endhead
 \hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
 \endfoot
 \hline
 \endlastfoot
 \begin{tabitem}    \item TEAM/ UNIT/ Organisation  \end{tabitem}  
 & \begin{tabitem}
 \item To maintain staff passion to maintain data provider trust in releasing 
 data because the data providers could get feedbacks during verifications.
 \end{tabitem}
 & \begin{tabenum}\item To explore the Idea of a merger* with  existing 
 expertise/resources in MOH to upgrade the hardcopy reports into electronic 
 version ie  bona fide Performance Dashboard possibly using the system that 
  has been developed. 
\item Use the prototype Performance Dashboard to help clients “see” its 
potentials to help them in their work, so that they can come up with what 
matters to them (direction) that eventually helps MHPU/PIK to revise their 
strategic plans/performance metrics
\end{tabenum}
&   \begin{tabitem} \item To maintain staff passion to maintain data 
provider trust in releasing data because the data providers could get 
feedbacks during verifications. 
\end{tabitem}  \\
\hline
\end{longtable}}

{\RaggedRight
 \begin{longtable}{|p{0.145\textwidth-2\tabcolsep-2\arrayrulewidth}|p{0.2\textwidth-2\tabcolsep-\arrayrulewidth}|p{0.455\textwidth-2\tabcolsep-\arrayrulewidth}|p{0.2\textwidth-2\tabcolsep-\arrayrulewidth}|}
 \caption{A simple longtable example}\\
 \hline
 \textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
 \hline
 \endfirsthead
 \multicolumn{4}{c}%
 {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
 \hline
 \textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
 \hline
 \endhead
 \hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
 \endfoot
 \hline
 \endlastfoot
 \begin{tabitem}    \item TEAM/ UNIT/ Organisation  \end{tabitem}  
 & \begin{tabitem}
 \item To maintain staff passion to maintain data provider trust in releasing 
 data because the data providers could get feedbacks during verifications.
 \end{tabitem}
 & \begin{tabenum}\item To explore the Idea of a merger* with  existing 
 expertise/resources in MOH to upgrade the hardcopy reports into electronic 
 version ie  bona fide Performance Dashboard possibly using the system that 
  has been developed. 
\item Use the prototype Performance Dashboard to help clients “see” its 
potentials to help them in their work, so that they can come up with what 
matters to them (direction) that eventually helps MHPU/PIK to revise their 
strategic plans/performance metrics
\end{tabenum}
&   \begin{tabitem} \item To maintain staff passion to maintain data 
provider trust in releasing data because the data providers could get 
feedbacks during verifications. 
\end{tabitem}  \\
\hline
\end{longtable}}
\end{document}

关于编辑的问题:

longtable只能在行之间分页。如果在单个表格行中有一个长列表,则此列表中不能有分页符,如您在示例中所见。要启用分页符,您可以将列表拆分为几行,并使用seriesandresume方法进行连续编号,如以下示例所示:

在此处输入图片描述

\documentclass[12pt]{article}
 \usepackage{longtable}
 \usepackage[landscape]{geometry}
 \usepackage{ragged2e}
 \usepackage{calc,array}

\usepackage{enumitem}
\newlist{tabitem}{itemize}{1}
\newlist{tabenum}{enumerate}{1}

\setlist[tabitem]{nosep,
                  topsep= 0pt,
                  partopsep=0pt,
                  leftmargin= *,
                  label=\textbullet,
                  before=\vspace{-0.6\baselineskip},
                  after=\vspace{-\baselineskip}
                  } 
 \setlist[tabenum]{nosep,
                  topsep= 0pt,
                  partopsep=0pt,
                  leftmargin= *,
                  label=\arabic*.,
                  before=\vspace{-0.6\baselineskip},
                  after=\vspace{-\baselineskip},
                  } 

 \begin{document}

{\RaggedRight
 \begin{longtable}{|p{0.145\textwidth-2\tabcolsep-2\arrayrulewidth}|p{0.2\textwidth-2\tabcolsep-\arrayrulewidth}|p{0.455\textwidth-2\tabcolsep-\arrayrulewidth}|p{0.2\textwidth-2\tabcolsep-\arrayrulewidth}|}
 \caption{A simple longtable example}\\
 \hline
 \textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
 \hline
 \endfirsthead
 \multicolumn{4}{c}%
 {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
 \hline
 \textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
 \hline
 \endhead
 \hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
 \endfoot
 \hline
 \endlastfoot
 \begin{tabitem}    \item TEAM/ UNIT/ Organisation  \end{tabitem}  
 & \begin{tabitem}
 \item To maintain staff passion to maintain data provider trust in releasing 
 data because the data providers could get feedbacks during verifications.
 \end{tabitem}
 & \begin{tabenum}[series=enum]\item To explore the Idea of a merger* with  existing 
 expertise/resources in MOH to upgrade the hardcopy reports into electronic 
 version ie  bona fide Performance Dashboard possibly using the system that 
  has been developed. 
\item Use the prototype Performance Dashboard to help clients “see” its 
potentials to help them in their work, so that they can come up with what 
matters to them (direction) that eventually helps MHPU/PIK to revise their 
strategic plans/performance metrics
\end{tabenum}
&   \begin{tabitem} \item To maintain staff passion to maintain data 
provider trust in releasing data because the data providers could get 
feedbacks during verifications. 
\end{tabitem}  \\
&& \begin{tabenum}[resume=enum] \item To explore the Idea of a merger* with  existing 
 expertise/resources in MOH to upgrade the hardcopy reports into electronic 
 version ie  bona fide Performance Dashboard possibly using the system that 
  has been developed. 
\item Use the prototype Performance Dashboard to help clients “see” its 
potentials to help them in their work, so that they can come up with what 
matters to them (direction) that eventually helps MHPU/PIK to revise their 
strategic plans/performance metrics
\end{tabenum} & \\
&& \begin{tabenum}[resume=enum] \item To explore the Idea of a merger* with  existing 
 expertise/resources in MOH to upgrade the hardcopy reports into electronic 
 version ie  bona fide Performance Dashboard possibly using the system that 
  has been developed. 
\item Use the prototype Performance Dashboard to help clients “see” its 
potentials to help them in their work, so that they can come up with what 
matters to them (direction) that eventually helps MHPU/PIK to revise their 
strategic plans/performance metrics
\end{tabenum} & \\
\hline
\end{longtable}}
\end{document}

答案2

正如您已经了解的那样,longtable环境只能在“行”的末尾创建分页符。但是,通过使第二个数据列的宽度约为其他两个列的四倍,可以将两个“行”放在longtable一页上。

在下面的代码中,我还自定义了itemizeenumerate环境,使它们占用尽可能少的空间。

由于列非常窄,我建议您从完全对齐切换到右对齐。

/另一个提示:你似乎经常使用符号(“斜线”)来形成单词对甚至三元组。LaTeX 通常不允许在符号处换行。我建议你用/替换所有实例(注意额外的空格);这样,换行符/\slash再次成为可能。例如,我建议您从 切换Team/Unit/OrganisationTeam\slash Unit\slash Organisation

在此处输入图片描述

\documentclass[12pt,a4paper]{article}
\usepackage{longtable}
\usepackage[margin=2cm,landscape]{geometry}
\usepackage[english]{babel}

\usepackage{array,ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}

\usepackage{enumitem}
%% customize 'itemize' and 'enumerate' environments:
\setlist[itemize]{wide=0pt,nosep,
    before = \vspace{-\baselineskip},
    after  = \vspace{-\baselineskip}}
\setlist[enumerate]{wide=0pt,nosep,
    before = \vspace{-\baselineskip},
    after  = \vspace{-\baselineskip}}


\begin{document}
\setlength\extrarowheight{1.5pt}

\begin{longtable}{|P{2.5cm}|P{4cm}|P{12cm}|P{4cm}|}

%% headers and footers

\caption{A single-page longtable example}\\
\hline
\textbf{Items} & \textbf{2018} & \textbf{2019} & \textbf{2020} \\
\hline
\endfirsthead

\multicolumn{4}{c}{\tablename\ \thetable,
 \textit{Continued from previous page}} \\
\hline
\textbf{Items} & \textbf{2018} & 
\textbf{2019}  & \textbf{2020} \\
\hline
\endhead

\hline 
\multicolumn{4}{r}{\textit{Continued on next page}} \\
\endfoot

\hline
\endlastfoot


%% body of table

\begin{itemize} 
\item TEAM\slash UNIT\slash Organisation  
\end{itemize}  
& 
\begin{itemize}
\item To maintain staff passion to maintain data provider trust in releasing data because the data providers could get feedbacks during verifications.
\end{itemize}
&  
\begin{enumerate}
\item To explore the Idea of a merger* with existing expertise\slash resources in MOH to upgrade the hardcopy reports into electronic version ie bona fide Performance Dashboard possibly using the system that has been developed. 
\item Use the prototype Performance Dashboard to help clients ``see'' its potentials to help them in their work, so that they can come up with what matters to them (direction) that eventually helps MHPU\slash PIK to revise their strategic plans\slash performance metrics
\end{enumerate}
& 
\begin{itemize} 
\item To maintain staff passion to maintain data provider trust in releasing data because the data providers could get feedbacks during verifications. 
\end{itemize}  
\\  % end of first "row"
\hline

Team\slash Unit\slash Organisation 
& 
To maintain staff passion to maintain data provider trust in releasing data because the data providers could get feedbacks during verifications.   
& 
\begin{enumerate}
\item To maintain staff passion to maintain data provider trust in releasing data because the data providers could get feedbacks during verifications.
\item To explore the Idea of a merger* with existing expertise\slash resources to upgrade the hardcopy reports into electronic version ie  bona fide Performance Dashboard possibly using the system that has been developed by 
\item Use the prototype Performance Dashboard to help clients ``see'' its potentials to help them in their work, so that they can come up with what matters to them (direction) that eventually helps MHPU\slash PIK to revise their strategic plans\slash performance metrics.
\item To explore the Idea of a merger* with existing expertise\slash resources in MOH to upgrade the hardcopy reports into electronic version ie bona fide Performance Dashboard possibly using the system that has been developed.
\item To explore the Idea of a merger* with existing expertise\slash resources to upgrade the hardcopy reports into electronic version ie bona fide Performance Dashboard possibly using the system that has been developed.
\end{enumerate}
& 
To maintain staff passion to maintain data provider trust in releasing data because the data providers could get feedbacks during verifications. 
\\ % end of second "row"
\end{longtable}
\end{document}

相关内容