I am looking to add a line around some text. The text may span multiple lines.

I found a solution here that perfectly does this but it is limited to single line and fails when I add a second line.

Single line solutions that were provided in the above link:

  1. \newcommand*\ruleline[1]{\par\noindent\raisebox{.8ex}{\makebox[\linewidth]{\hrulefill\hspace{1ex}\raisebox{-.8ex}{#1}\hspace{1ex}\hrulefill}}}
  2. \def\headline#1{\hbox to \hsize{\hrulefill\quad\lower.3em\hbox{#1}\quad\hrulefill}}

Looking for something like this:


2 Answers 2


Try this:

\noindent\tikz\draw (0,0)--(\linewidth,0) node[text centered,midway,fill=white,text width=30mm] () {Text\\More text\\and more text};


enter image description here

Solved: Try this code:

\noindent\tikz\draw (0,0)--(\linewidth,0) node[align=center,text centered,fill=white,midway] () {Text\\More text\\and more loong text};


enter image description here

  • can 'text width=30mm' be set to variable width such that it adapts to line length?
    – Furqan136
    Commented Jun 2, 2023 at 12:04
  • @Furqan136 See my edit in the answer. Commented Jun 2, 2023 at 15:01

With the package varwidth

the code

\noindent\hrulefill \raisebox{-0.5ex}{\begin{varwidth}{\textwidth}
            \centering Text\\More text\\and more loong text

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .