When borders around a rectangular node is drawn, some space is also added, as can be seen by the example below.
\documentclass{article}
\usepackage[papersize={70mm,34mm}]{geometry}
\usepackage{tikz}
\tikzset{
boxdraw/.style={very thick,rounded corners,fill=yellow!30, },
}
\newcommand{\firstline}[1]{%
\noindent
\begin{tikzpicture}
\node[text width=\linewidth](p){#1};
\draw[boxdraw] (p.south west) -- (p.north west) -- (p.north east) -- (p.south east);
\node[text width=\linewidth]{#1};
\end{tikzpicture}%
\newline
}
\newcommand{\middleline}[1]{%
\noindent
\begin{tikzpicture}
\node[text width=\linewidth,fill=yellow!30](p){#1};
\draw[boxdraw] (p.north west) -- (p.south west) (p.north east) -- (p.south east);
\end{tikzpicture}%
\newline
}
\newcommand{\lastline}[1]{%
\noindent
\begin{tikzpicture}
\node[text width=\linewidth](p){#1};
\draw[boxdraw] (p.north west) -- (p.south west) -- (p.south east) -- (p.north east);
\node[text width=\linewidth](p){#1};
\end{tikzpicture}%
}
\splittopskip 0pt
\baselineskip 0pt
\lineskiplimit 0pt
\lineskip 0pt
\begin{document}
\firstline{This is the first line}
\middleline{and this is my second line}
\middleline{followed by another middle line}
\lastline{followed by this one last line.}
\end{document}
Look at the space between the lines.
If the line
\draw[boxdraw] (p.north west) -- (p.south west) (p.north east) -- (p.south east);
(which draws the border around the rectangle node) is commented out in the definition of \middleline
, the space between middle lines are not present.
How can these spaces be completely removed while keeping the borders?
EDITED: A brief explanation of the purpose of these macros
I am trying to write a package for boxes that may break across pages. I know there are already some packages for that (like mdframed
and tcolorbox
), but most of them fail to break inner boxes in nested boxes. With nested boxes, only the outermost box can be breakable. That is due to the algorithm they implement for breaking boxes. I want to overcome this issue by using a different splitting algorithm, based on the one employed by the boites
package.
The algorithm I am going to use first gets the contents of the breakable box into a vbox
. Then the vbox
is split into its individual lines. Then each line receives a background colour and a frame.
The macros \firstline
, \middleline
and \lastline
would be used to give a background colour and a frame to each of those lines. Because of framing, I will need one macro for the first line of the breakable box, one for middle lines, and one for the last line.
outer sep
.outer sep=0pt
does not help. Setting it to a negative value may suppress the space, but the borders are also reduced, what is not acceptable.\node[draw, very thick, rounded corners, fill=yellow!30, text width=\linewidth] {This is the first line\\and this is my second line\\followed by another middle line\\followed by this one last line.};
?