删除表格环境中“itemize”列表上方的空间

删除表格环境中“itemize”列表上方的空间

我想itemizetable-environment 中包含一个 -list,以紧凑的方式节省空间。但是,在表格中时,列表上方有一个很大的间隙,但在普通文本中的段落之后则没有:

\documentclass[12pt]{scrbook}
%\usepackage[autooneside=false, headsepline, plainheadsepline, automark]{scrlayer-scrpage}
\linespread{1}
\usepackage{paralist}
\usepackage{enumitem} % enumerate?
\usepackage{tabularx}

\begin{document}
some text
\begin{compactitem}  \item  point1  \item point2 \end{compactitem}
\begin{table}[ht!]
    \setlength{\leftmargini}{7pt}
    \begin{tabularx}{\linewidth}{l | X | X }\hline \hline
        & ECB& FED\\ \hline
    M1 & \begin{itemize}[noitemsep,topsep=0pt]   \item  point1  \item point2 \end{itemize} 
      & \begin{compactitem}  \item  point1  \item point2   \end{compactitem}
    \end{tabularx}
\end{table}

\end{document}

如您所见,我测试了compactitemfromparalist包以及itemizefromenumitem及其选项[noitemsep,topsep=0pt]。它们产生的高度略有不同。这在普通段落之间有效,但在表格中无效。我希望“point1”与“M1”处于同一水平。

在此处输入图片描述


这个,在换行时可以看到轻微的缩进(“Assets”这个词比“during”这个词更靠右一点),是

\begin{minipage}[t]{\hsize}\begin{compactitem}
 \item Assets can be \textbf{difficult to value} during periods of hyperinflation
\end{compactitem}\end{minipage}

在此处输入图片描述


比较两种提出的解决方案:下面的 MWE 直接比较了这两种解决方案,分别定义了新的环境,名为compactitemtcompactitemm

\documentclass%[12pt,abstracton,titlepage,parskip=false, no, no,twoside=true,open=right]
{scrbook}
%\usepackage[autooneside=false, headsepline, plainheadsepline, automark]{scrlayer-scrpage}

%\usepackage{listings}
\usepackage{paralist}
%\usepackage{newtxtext}%antpolt mathpazo %\usepackage{mathptmx} %\usepackage{newtxtext} 
\usepackage{enumitem} % enumerate?
\newenvironment{compactitemm}{\begin{minipage}[t]{\hsize}\begin{compactitem}}{\end{compactitem}\end{minipage}} %this solution requires enumitem package
\newenvironment{compactitemt}{\begin{itemize}[nosep, wide=0pt,
  %left=0pt %for neat, wide=0pt %for flush left to save space
  before={\begin{minipage}[t]{\hsize}},
  after ={\end{minipage}} ]   }{ \end{itemize} }
\renewcommand{\familydefault}{\sfdefault}

\usepackage{tabularx}

\begin{document}

\begin{table}
\setlength{\leftmargini}{7pt} %this impacts the left margin of itemize package, i.e. ``stuff 2'' in table. 7pt aligns with the other solution. 
\begin{tabularx}{\linewidth}{X | X }\hline
\multicolumn{2}{c}{stuff 1}\\ \hline
\begin{compactitemt}
  \item x This line should break and we see where the next begins
  \item y
  \item z
\end{compactitemt}
& \begin{compactitemt}
  \item a This line should break and we see where the next begins
  \item b
\end{compactitemt}\\ \hline 
\multicolumn{2}{c}{stuff 2}\\ \hline
\begin{compactitemm}
  \item x This line should break and we see where the next begins
  \item y
  \item z This line should break and we see where the next begins
\end{compactitemm}
& \begin{compactitemm}
  \item a This line should break and we see where the next begins
  \item b
\end{compactitemm}\\ \hline 
\end{tabularx}
\caption{MWE}
\end{table}

\end{document}

在此处输入图片描述

答案1

  • 如果您使用compactitem环境,则需要将其括在\begin{minipage}[t]{\hsize}and\end{minipage}语句中。
  • 如果您itemizeenumitem包一起使用环境,则可以添加语句

    before={\begin{minipage}[t]{\hsize}},
    after ={\end{minipage}}
    

    添加到随附的选项列表中\begin{itemize}

在此处输入图片描述

\documentclass[12pt]{scrbook}
\usepackage{paralist,enumitem,tabularx}
\begin{document}

\begin{table}[ht!]
    \setlength\extrarowheight{2pt} % optional, for a slighly more open "look"
    \setlength{\leftmargini}{7pt}
    \begin{tabularx}{\linewidth}{l | X | X }
    \hline \hline
       & ECB & FED\\ 
    \hline
    M1 & \begin{itemize}[nosep, left=0pt,
                         before={\begin{minipage}[t]{\hsize}},
                         after ={\end{minipage}} ]   
         \item point1  
         \item point2 
         \end{itemize} 
       & \begin{minipage}[t]{\hsize}
         \begin{compactitem}  
         \item point1  
         \item point2   
         \end{compactitem}
         \end{minipage}\\
    \hline
    \end{tabularx}
\end{table}

\end{document}

答案2

对于上面的空间,让 LaTeX 相信单元格是小页面就足够了。为此,我借用了\compress此网站问题答案中的一个命令。对于下面的空间,您必须在末尾添加一个负数 \baselineskip。

\documentclass[12pt]{scrbook}
%\usepackage[autooneside=false, headsepline, plainheadsepline, automark]{scrlayer-scrpage}
\linespread{1}
\usepackage{paralist}
\usepackage{enumitem} % enumerate?
\usepackage{tabularx}
\makeatletter
\newcommand{\compress}{\@minipagetrue}
\makeatother

\begin{document}
some text
\begin{compactitem} \item point1 \item point2 \end{compactitem}
\begin{table}[ht!]
    \setlength{\leftmargini}{7pt}
    \begin{tabularx}{\linewidth}{l | >{\compress}X |>{\compress} X }\hline \hline
        & ECB& FED\\ \hline
    M1 & \begin{itemize}[nosep, after=\vspace{-\baselineskip}] \item point1 \item point2 \end{itemize}\\
\hline
    & & \begin{compactitem} \item point1 \item point2 \end{compactitem}\leavevmode\vspace*{-\baselineskip}
       \\
\hline
    \end{tabularx}
\end{table}

\end{document} 

为此,我借用了 `` \copress` 命令,找到了一个

相关内容