删除两行之间的空格

删除两行之间的空格

我找不到,如何删除这里块之间的空间?(fbox 最终将被删除,它们只是用来显示问题)更一般地说,我该如何调试它以找出造成问题的原因?

在此处输入图片描述

梅威瑟:

\documentclass[]{article}

\usepackage[most]{tcolorbox}
\usepackage{enumitem}

\NewDocumentEnvironment{cvArray}{m}{%
  \def\currentColorIndex{0}%
  \NewDocumentCommand{\cvItem}{m+m}{%
    \ifnum\currentColorIndex=0%
      \def\currentColor{white}%
    \else%
      \def\currentColor{blue!7!white}%
    \fi%
    \pgfmathsetmacro\currentColorIndex{int(mod(\currentColorIndex+1,2))}%
    \noindent\setlength\fboxsep{0pt}\fbox{\noindent\begin{tcolorbox}[enhanced,title=,
        frame hidden,
        colback=\currentColor,
        breakable,
        left=5pt,
        right=10pt,
        top=5pt,
        bottom=5pt,
        boxsep=0mm,
        arc=0mm,boxrule=0pt,
        nobeforeafter, 
        ]
        \begin{enumerate}[nosep,leftmargin=#1]
        \item[{\raisebox{0pt}[\height][0pt]{%
              \parbox[t]{#1}{\centering ##1}%
            }}] ##2
          % \item[AAA] ##2
        \end{enumerate}
      \end{tcolorbox}}
  }%
}{%
}

\begin{document}

How to remove the small space between the boxes?

\begin{cvArray}{4cm}
  \cvItem{Foo}{ Blaa bla}
  \cvItem{Foo}{ Blaa bla}
  \cvItem{Foo}{ Blaa bla}
  \cvItem{Foo}{ Blaa bla}
  \cvItem{Foo}{ Blaa bla}
\end{cvArray}
\end{document}

答案1

您可以使用类似的方法\offinterlineskip来关闭行间空格:

\documentclass[]{article}

\usepackage[most]{tcolorbox}
\usepackage{enumitem}

\NewDocumentEnvironment{cvArray}{m}{%
  \def\currentColorIndex{0}%
  \NewDocumentCommand{\cvItem}{m+m}{%
    \ifnum\currentColorIndex=0%
      \def\currentColor{white}%
    \else%
      \def\currentColor{blue!7!white}%
    \fi%
    \pgfmathsetmacro\currentColorIndex{int(mod(\currentColorIndex+1,2))}%
    \noindent\setlength\fboxsep{0pt}\fbox{\noindent\begin{tcolorbox}[enhanced,title=,
        frame hidden,
        colback=\currentColor,
        breakable,
        left=5pt,
        right=10pt,
        top=5pt,
        bottom=5pt,
        boxsep=0mm,
        arc=0mm,boxrule=0pt,
        nobeforeafter, 
        ]
        \begin{enumerate}[nosep,leftmargin=#1]
        \item[{\raisebox{0pt}[\height][0pt]{%
              \parbox[t]{#1}{\centering ##1}%
            }}] ##2
          % \item[AAA] ##2
        \end{enumerate}
      \end{tcolorbox}}
  }%
}{%
  \offinterlineskip\par
}

\begin{document}

How to remove the small space between the boxes?

\begin{cvArray}{4cm}
  \cvItem{Foo}{ Blaa bla}
  \cvItem{Foo}{ Blaa bla}
  \cvItem{Foo}{ Blaa bla}
  \cvItem{Foo}{ Blaa bla}
  \cvItem{Foo}{ Blaa bla}
\end{cvArray}%


\end{document}

在此处输入图片描述

答案2

你把事情搞得太复杂了。\fbox当你正在做一个tcolorbox具有完整框架功能的东西时,为什么要使用它呢?

为什么要使用\parbox不凸起而只是压在底部的,而您显然不希望在第一个参数中使用多行?为什么要使用enumerate单个项目?

解决方案是将其设置\lineskip为规则厚度的负数,这样连续的规则就会重叠。但是,我也为项目重置了\lineskip标准\parbox

\documentclass[]{article}

\usepackage[many]{tcolorbox}

\usepackage{lipsum}

\newlength{\normallineskip}

\NewDocumentEnvironment{cvArray}{m}{%
  \setlength{\normallineskip}{\lineskip}% 
  \setlength{\lineskip}{-0.4pt}% back up by the rule width
  \def\currentColorIndex{0}%
  \NewDocumentCommand{\cvItem}{m+m}{%
    \ifodd\currentColorIndex
      \def\currentColor{blue!7!white}%
    \else
      \def\currentColor{white}%
    \fi
    \edef\currentColorIndex{\inteval{\currentColorIndex+1}}%
    \begin{tcolorbox}[
      enhanced,
      title=,
      sharp corners,
      colback=\currentColor,
      breakable,
      left=5pt,
      right=10pt,
      top=5pt,
      bottom=5pt,
      boxsep=0mm,
      arc=0mm,
      boxrule=0.4pt,
      nobeforeafter, 
    ]
    \makebox[#1]{##1}\parbox[t]{\dimeval{\linewidth-#1}}{%
      \setlength{\lineskip}{\normallineskip}%
      ##2%
    }%
    \end{tcolorbox}%
  }%
}{\par}

\begin{document}

\begin{cvArray}{4cm}
  \cvItem{Foo}{\lipsum[1][1-2]}
  \cvItem{Foo}{Blaa bla}
  \cvItem{Foo}{Blaa bla}
  \cvItem{Foo}{Blaa bla}
  \cvItem{Foo}{Blaa bla}
\end{cvArray}

\end{document}

在此处输入图片描述

相关内容