长表内的 minipage 给出了额外的新行

长表内的 minipage 给出了额外的新行

我定义了一个新环境,为小页面添加顶部和底部填充,并在单独的表格单元格内使用(我已使用 \linewidth 指定新环境中小页面的宽度)。但它为以下枚举提供了额外的换行符。参见图像的第 2 行。

在此处输入图片描述

\documentclass[a4paper,12pt, oneside]{book}

%tweek font spacing for better look
\usepackage{microtype}

%enable linespacing commands%
\usepackage{setspace}

%enable H option that prevent figure floats
\usepackage{float}

%used to import graphics%
\usepackage{graphicx}

%used for referencing%
\usepackage{harvard}

%customise chapter styles%
\usepackage{titlesec}

%set margins%
\usepackage[left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}

%allows to create tables with different column widths%
\usepackage{tabularx}

%allows to create tables that can span across pages%
\usepackage{longtable}%dependency of longtabu (bug fix patch applied)
\usepackage{tabu}%contains longtabu

%enable support for source code
%this package needs the python package 'sudo pip install pygments'
%add pdfLaTeX option -shell-escape
\usepackage{minted}

%enables itemize space customization options
\usepackage{enumitem}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newenvironment{stablecell}{
\begin{minipage}{\linewidth}
\vspace{2mm}
}{
\vspace{1mm}
\end{minipage}
}

\newenvironment{spackenum}{
\begin{enumerate}[noitemsep,topsep=0pt,parsep=0pt,partopsep=0pt,leftmargin=*]
}{
\vspace{1mm}
\end{enumerate} 
}

\newenvironment{spackitems}{
\begin{itemize}[noitemsep,topsep=0pt,parsep=0pt,partopsep=0pt,leftmargin=*]
}{
\vspace{1mm}
\end{itemize} 
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

%keep only the page number%
\pagestyle{plain}

%set onehalf line spacing
\onehalfspacing

%customise chapter styles from titlesec%
\titleformat{\chapter}{}{}{0em}{\bf\LARGE}

%set bibliography listing style to agsm%
\bibliographystyle{agsm}


%%%%%%%%%%%%%%%% Table Start %%%%%%%%%%%%%%%%%%%%
\begin{longtabu} to \textwidth { X[1 , l ]  X[4.1 , l ] }
\caption{xxxxxxxx}\label{table:xxxxxx}\\
%%%%%%%%%%%%%%%% Heading Start %%%%%%%%%%%%%%%%%%
\hline
\endfirsthead
%==============================================
%Next page headings
\hline
\endhead
%==============================================
%Before page break text
\endfoot
%==============================================
\hline
\endlastfoot
%%%%%%%%%%%%%%%% Heading End %%%%%%%%%%%%%%%%%%
%\hline
\textbf{what i want}
& \begin{stablecell}
\begin{spackenum}
\item xxxx xxxxx xxxx xxxxxx xxxxx xxx
\item xxxx xxxxx xxxx xxxxxx xxxxx xxx
\end{spackenum} 
\end{stablecell}\\
%==============================================
\hline
\textbf{without minipage}
&\begin{spackenum}
\item xx xxxxx xxxx xxxxxx.
\item xxxx xxxxx xxxx xxxxxx xxxxx xxxxxxx xxxxx xxxx xxxxxx.
\end{spackenum} \\
%==============================================
\hline
\textbf{extra line}
& \begin{stablecell}
\begin{spackenum}
\item xx xxxxx xxxx xxxxxx.
\item xxxx xxxxx xxxx xxxxxx xxxxx xxxxxxx xxxxx xxxx xxxxxx.
\end{spackenum} 
\end{stablecell}\\
%%%%%%%%%%%%%%%%% Body End %%%%%%%%%%%%%%%%%%%%
\end{longtabu}
%%%%%%%%%%%%%%%% Table End %%%%%%%%%%%%%%%%%%%%


\end{document}

答案1

问题是由于您将\vspace命令放置在环境末尾的位置造成的。将它们放置在环境给出了预期的间距:

示例输出

\documentclass[a4paper,12pt, oneside]{book}

\usepackage{setspace}

\usepackage[left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}

\usepackage{tabularx}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{enumitem}

\newenvironment{stablecell}{\begin{minipage}{\linewidth}
\vspace{2mm}
}{\end{minipage}\vspace{1mm}}

\newenvironment{spackenum}{%
\begin{enumerate}[noitemsep,topsep=0pt,parsep=0pt,partopsep=0pt,leftmargin=*]
}{\end{enumerate}\vspace{1mm}}

\begin{document}

\onehalfspacing

\begin{longtabu} to \textwidth { X[1 , l ] X[4.1 , l ] }
  \caption{xxxxxxxx}\label{table:xxxxxx}\\
  \hline \endfirsthead \hline \endhead \endfoot \hline \endlastfoot
  \textbf{what i want} & \begin{stablecell}
    \begin{spackenum}
    \item xxxx xxxxx xxxx xxxxxx xxxxx xxx
    \item xxxx xxxxx xxxx xxxxxx xxxxx xxx
    \end{spackenum}
  \end{stablecell}\\
  \hline \textbf{without minipage} &\begin{spackenum}
  \item xx xxxxx xxxx xxxxxx.
  \item xxxx xxxxx xxxx xxxxxx xxxxx xxxxxxx xxxxx xxxx xxxxxx.
  \end{spackenum} \\
  \hline \textbf{no extra line} & \begin{stablecell}
    \begin{spackenum}
    \item xx xxxxx xxxx xxxxxx.
    \item xxxx xxxxx xxxx xxxxxx xxxxx xxxxxxx xxxxx xxxx xxxxx.
    \end{spackenum}
  \end{stablecell}\\
\end{longtabu}

\end{document}

一般来说,最好使用\addvspace,这样可以确保最小的空间量,但不会累积连续的垂直空间。

相关内容