# Texts above and below one filling horizontal rule

Here is a starting code for a template to write sheets of exercises.

\documentclass[12pt]{article}
\usepackage{xhfill}   % https://tex.stackexchange.com/a/155960/6880
\usepackage[showframe]{geometry}

\begin{document}

START

\setlength{\fboxrule}{0.2ex}
\framebox{Ex.1}\xrfill[0.4ex]{0.25ex}

\end{document}


I would like to add materials above and below the filling rule like in the following picture. How can I achieve this ?

You can set a zero-width box with content raised/lowered into position:

\documentclass{article}

\usepackage{xhfill}
\usepackage[showframe]{geometry}

\begin{document}

START

\setlength{\fboxrule}{0.2ex}%
\framebox{Ex.1}\xrfill[0.4ex]{0.25ex}%
\makebox[0pt][r]{\raisebox{.5\baselineskip}[0pt][0pt]{\scshape above}}%
\makebox[0pt][r]{\raisebox{-.6\baselineskip}[0pt][0pt]{\scshape below}}%

\end{document}


The raised/lowered text is set with 0pt height/depth so it doesn't affect the line spacing for surrounding content.

• Thanks. I have to learn to play more seriously with boxes... – projetmbc Nov 13 '17 at 23:27

You can use stackengine's top and bottom lapping macros. Here \tllap is a top-left lap, and \bllap is a bottom-left lap. The optional argument provides the baseline skip of the lap. The % at line end is necessary to avoid stray spaces before or between laps.

\documentclass[12pt]{article}
\usepackage{xhfill}   % https://tex.stackexchange.com/a/155960/6880
\usepackage[showframe]{geometry}
\usepackage{stackengine}
\begin{document}

START

\setlength{\fboxrule}{0.2ex}
\framebox{Ex.1}\xrfill[0.4ex]{0.25ex}%
\tllap[6pt]{Here}%
\bllap[9pt]{and There}

\end{document}


• Shorter to write. Thanks for this short version. – projetmbc Nov 13 '17 at 23:30