2

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 ?

enter image description here

Johannes_B
  • 24,235
  • 10
  • 93
  • 248
projetmbc
  • 13,315

2 Answers2

1

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

enter image description here

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

Werner
  • 603,163
1

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}

enter image description here