1

I wish to put a horizontal line above tabbing and another one below it in such a way that there are no page breaks between the tabbing contents and the two lines. Here is what I tried so far:

\documentclass[a4paper]{article}
\newenvironment{ruletabbing}{%
\begingroup\setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}\raggedright\hrule\nopagebreak\tabbing\nopagebreak%
}{%
\nopagebreak\endtabbing\nopagebreak\vspace{-.05\baselineskip}\nopagebreak\hrule\par\vspace{.07\baselineskip}\endgroup%
}
\begin{document}
\strut
\vspace{46.8\baselineskip}\\
A page break after this text would be ok.\\[.1\baselineskip]
\begin{ruletabbing}
  A page break after this text in tabbing, but not before it, would be ok.\\
  A page break before this text in tabbing, but not after it, would be ok.
\end{ruletabbing}
\noindent A page break before this text would be ok.
\end{document}

However, the \nopagebreaks seem to have no effect; this example blatantly fails:

output

Above, there is a page break right after the first rule, which is NOT what we want. If it doesn't fail for you, adapt 46.8 above slightly. The same problem we have for the second line, by means of changing 46.8 to a particular smaller value.

How to forbid page breaks between the two horizontal lines and the tabbing contents? The tabbing conents should be allowed to have page breaks inside by all means. Ideally, the new tabbing environment should also work inside lists (itemize, enumerate, description), though it's not a must.

0

User-almost-half-a-million probably isn't reading, but preventing the page breaks around a tabbing environment is a fairly simple matter of telling the tabbing not to promote breaks in those places, as it normally does. Those settings would go in the same place as one puts the settings that prevent the extra white space.

\makeatletter
\newenvironment{ruletabbing}{%
  \setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}%
  \raggedright
  \@nobreaktrue % no favorable break at start
  \@endparpenalty=10000 % no favorable break at end
  \hrule\nopagebreak\tabbing
}{%
  \endtabbing
  \vspace{-.05\baselineskip}\hrule\vspace{.07\baselineskip}%
}
\makeatother

I have copied the spacing, but note that \hrule is problematic because it does not play nice with normal interline spacing rules.

| improve this answer | |
  • Oops, yes! Hi! For the \hrule I was thinking of how the positioning is sensitive to the presence or absence of descenders on letters. My preference would be a rule inside \hbox, or some adjustment of/from the \prevdepth to get something akin to how \baselineskip is applied between lines. – Donald Arseneau Jun 29 at 4:21
0

You can use tcolorbox

\documentclass{book} 
\usepackage{tcolorbox} 

\begin{document}
\begin{tcolorbox}[boxrule=0mm,toprule=1mm,bottomrule=1mm,colback=white,arc=0mm]
content
\end{tcolorbox}

\end{document}

or

\documentclass{book} 
\usepackage{tcolorbox} 
\newenvironment{ruletabbing}{%
\begingroup\setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}\raggedright\hrule\nopagebreak\tabbing\nopagebreak%
}{%
\nopagebreak\endtabbing\nopagebreak\vspace{-.05\baselineskip}\nopagebreak\hrule\par\vspace{.07\baselineskip}\endgroup%
}

\begin{document}
\begin{tcolorbox}[boxrule=0mm,toprule=0mm,bottomrule=0mm,colback=white,arc=0mm]
\begin{ruletabbing}
  A page break after this text in tabbing, but not before it, would be ok.\\
  A page break before this text in tabbing, but not after it, would be ok.
\end{ruletabbing}
\end{tcolorbox}

\end{document}
| improve this answer | |
  • @user0 sandu edited his answer. Is his answer ok now? – user156344 Mar 6 '19 at 5:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy