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

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}
  • @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

Not the answer you're looking for? Browse other questions tagged or ask your own question.