0

ich have the following code:

    \begin{center}
      \rule{0.2\linewidth}{0.1mm}\hspace{0.5em}
      \textbf{\large Analytische Aufgaben}\hspace{0.5em}
      \rule{0.2\linewidth}{0.1mm}
    \end{center}

What i want is that the text ist in between the lines like this:
|-------------- Analytische Aufgaben ------------|
The "----" should be on line and fill across the full horizontal page. "|" indicates the ends of the page.

I've tried multiple things but didn't get it workling.

Thanks

2 Answers2

2

You might try the package xhfill, but its documentation is very poor.

Alternatively

\documentclass{article}

\newcommand{\myfillrule}{% \leavevmode \leaders \hrule height\dimeval{0.5ex+0.2pt} depth \dimeval{-0.5ex+0.2pt}% \hfill\hspace*{0pt}% }

\begin{document}

\begin{center} \large \myfillrule\enspace Analytische Aufgaben\enspace \myfillrule \end{center}

\end{document}

enter image description here

If you want to change the thickness, replace the two occurrences of 0.2pt with half the desired dimension.

If you prefer that the rules are vertically centered with respect to uppercase letters, use

\documentclass{article}

\newcommand{\myfillrule}{% \leavevmode \leaders \hrule height\dimeval{0.5\fontcharht\fontA+0.2pt} depth \dimeval{-0.5\fontcharht\fontA+0.2pt}% \hfill\hspace*{0pt}% }

\begin{document}

\begin{center} \large \myfillrule\enspace Analytische Aufgaben\enspace \myfillrule \end{center}

\end{document}

with the same suggestion as above about the thickness.

enter image description here

egreg
  • 1,121,712
1

you could easy define a new centered rule like in the following:

\documentclass[%
]{article}
\usepackage[T1]{fontenc}
\usepackage[%
%showframe % Uncomment this to see the frames of the textbody
]{geometry}

\def\centerrulefill{\leavevmode\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}

\begin{document}

\begin{center} \centerrulefill\space \textbf{\large Analytische Aufgaben}% \space\centerrulefill \end{center}

\end{document}

Further options are described here.

But if you want to use this, for example, as a section heading, there are other packages and options.

lukeflo
  • 1,555