3

I can't find, how to remove the space between the blocks here? (the fbox will ultimately be removed, they are just used to show the problem) And more generally, how could I debug this in order to find what is posing a problem?

enter image description here

MWE:

\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
  • 2
    Or just set \lineskip=0pt temporarily. Commented Nov 9, 2023 at 20:43

2 Answers 2

2

You could use something like \offinterlineskip to switch the space between lines off:

\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}

enter image description here

2
  • Oh it is the first time I heard about this, I was trying to set \baselineskip to 0 but it was not working. Thanks!
    – tobiasBora
    Commented Nov 9, 2023 at 20:08
  • 1
    I hope nobody minds that the tail of the "p" in the text line above bashes into the top of the box. (Or is it that the box is doing the bashing?) Commented Nov 9, 2023 at 22:07
4

You're overcomplicating things. Why using \fbox when you're doing a tcolorbox that has full capabilities of making a frame?

Why using a \parbox that's not raised and just smashed at the bottom when, obviously, you don't want multiple lines in the first argument? Why using enumerate for a single item?

The solution is to set \lineskip to the negative of the rule thickness, so the consecutive rules will overlap. However, I also reset the standard \lineskip in the \parbox for the items.

\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}

enter image description here

3
  • Thanks! Regarding the overly complicated solution, as I sayed above, the frame is just used to show the problem (this way I can be sure that the space does not come from tcolorbox), and I will remove it. The first argument actually sometimes need multi-line items, hence the smashing, and I use enumerate because the text might be split on several pages, as advised in my previous question tex.stackexchange.com/questions/700676/…
    – tobiasBora
    Commented Nov 9, 2023 at 22:23
  • @tobiasBora If you smash the first argument it will overlap what's below. The \fbox was among the causes of the problem, actually.
    – egreg
    Commented Nov 9, 2023 at 22:36
  • yes, I know that this could overlap, but I found no other robust method (so for now if the left part is longer than the right part, I just add new lines on the right). Oh, interesting.
    – tobiasBora
    Commented Nov 9, 2023 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .