4

I have a piece of text (to be precise, a chapter heading) that is preceded and followed by a rule. The code looks as follows:

\documentclass[a4paper, 12pt]{book}
\usepackage{titlesec}

\begin{document}
    \noindent\rule[\baselineskip]{6cm}{.4pt}\\
    \textbf{SOME HEADER} \\ \\
    \rule[\baselineskip]{6cm}{.4pt}

    \titleformat{\chapter}[block]{}{}{0pt}
    {%
        {\large\MakeUppercase\thechapter\\}
        \hrule
        \vspace{\baselineskip}      
        \hbox{\LARGE\bfseries}
    }   
    [\LARGE\vspace{\baselineskip}\hrule]

    \chapter{Test}

\end{document}

which yields

enter image description here

Now - I want the white space above and below the text to be of equal size, which can be achieved by centering the text vertically in the "space" that is reserved for the line it is in (so basically, I want to lift the text a little bit from its baseline).

How can I do this? I've been fiddling around with boxes (especially \raisebox seems promising), but I get confused by how they work and have not managed to get exactly what I want. I am looking for the most simple solution.

EDIT: David Carlisle's solution works in the running text, but I actually want to use it in the \titleformat (from the titlesec package) command. The updated example would look something like this (I am aware that I can use \thechapter in the \titleformat's "label" field, but there is a reason why I am not doing that):

\documentclass[a4paper, 12pt]{book}
\usepackage{titlesec}

\begin{document}
    \titleformat{\chapter}[block]{}{}{0pt}
    {%
        {\large\MakeUppercase\thechapter\\}
        \hrule
        \vspace{\baselineskip}      
        \hbox{\LARGE\bfseries}
    }   
    [\LARGE\vspace{\baselineskip}\hrule]

    \chapter{SOME HEADER}

    % The chapter header is not as I want it, but in the running text this works:
    \noindent\rule[\baselineskip]{6cm}{.4pt}\\
    \textbf{SOME HEADER} \\ \\
    \rule[\baselineskip]{6cm}{.4pt}

\end{document}

... but now I get two new problems:

(1) The text is neither bold nor \LARGE
(2) The text is not centered vertically between the lines

Is what I want even possible?

1
  • Please post a complete compilable document, with documentclass and minimal text (as above). That makes it easier for folks here to grab the code and help you fix it. Commented Dec 18, 2015 at 13:48

2 Answers 2

4

Probably easier to use the primitives here

enter image description here

\documentclass{article}

\begin{document}
\showoutput

\hrule
\hbox{\textbf{SOME HEADER}}
\hrule

\bigskip

\hrule
\vskip5pt
\hbox{\textbf{SOME HEADER}}
\vskip5pt
\hrule



\end{document}
1

\vspace should do the job. Here below the complete example on top of your code, you can customize the vertical space that suits you, here 2cm used:

\documentclass{article}
\begin{document}
\noindent\rule[\baselineskip]{6cm}{.4pt}
\vspace{2cm}

\textbf{SOME HEADER}\\
\vspace{2cm}

\noindent\rule[\baselineskip]{6cm}{.4pt}
\end{document}

Notice that the blank line after the \vspace is on purpose.

2
  • 1
    don't tell @egreg you used \vspace ;)
    – Rico
    Commented Dec 18, 2015 at 14:49
  • 1
    @Rico Why not? I'd avoid \\ followed by \vspace, of course.
    – egreg
    Commented Dec 18, 2015 at 21:38

You must log in to answer this question.

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