# Center-justify with hrule above and below

On my title page, I have something like this:

\rule{\linewidth}{0.25mm}\\[0.25cm]
\huge
\textbf{This is my title, it is somewhat long and split over two lines!}\\[0.25cm]
\normalsize
\rule{\linewidth}{0.25mm}


and this is the corresponding output:

--------------------------------------
This is my title, it is somewhat
long and split over two lines!
--------------------------------------


Notice two things:

1. The top first and the (wrapped) second line are similar, but different lengths. I would like to justify them (compress the top line slightly, and expand the bottom slightly).
2. The \rule is extended to the \linewidth, whereas I would like it to be the width of the text in between the rules.

The result I'd like is something like:

--------------------------------
This is my title, it is somewhat
long and  split over  two lines!
--------------------------------


Any help with how to accomplish this? Thank you :)

-
You probably want to have a look at the shapepar package. –  nplatis Feb 9 '12 at 23:23

Pilfering from @egreg's answer... You could modify the inter-word spacing or just add a couple of \hfills inbetween:

\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\begin{document}

\mbox{\huge\bfseries
\begin{tabular}{@{}c@{}}
\toprule[.25mm]
This is my title, it is somewhat\\
long\hfill and\hfill split\hfill over\hfill two\hfill lines!\\
\bottomrule[.25mm]
\end{tabular}%
}

\end{document}


On its own, \hfill will do nothing inside a tabular if there isn't enough room to stretch. However, since the first line is longer than the second, there is room to stretch.

\makebox[<len>][<justification>]{<stuff>} can also be used with <justification> given by [s] (for stretch) if you know the <len> that <stuff> should be spread over:

\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\begin{document}

\newlength{\mylen}
\noindent{\huge\bfseries
\settowidth{\mylen}{This is my title, it is somewhat}%
\begin{tabular}{@{}c@{}}
\toprule[.25mm]
This is my title, it is somewhat\\
\makebox[\mylen][s]{long and split over two lines!}\\
\bottomrule[.25mm]
\end{tabular}%
}

\end{document}

-
This is great. The stretching on the second line in my real title is not very noticeable as with the carefully selected dummy title. The only thing which would make it better would be to slightly decrease the spacing between the words/letters in the top line to average out the expansion/contraction between both lines. Otherwise thanks! –  Ozzah Feb 9 '12 at 23:54
@Ozzah: The post How to enlarge interword space? may be of help. You would just use a factor of (say) 0.5 instead of 1.5 as suggested in the answer. –  Werner Feb 9 '12 at 23:57
I got rid of the \hfill's and put the top line inside a \textls[-10]{} and the bottom line in a \textls[10]{} and now it looks perfect. Obviously the 10/-10 is determined by the words on each line, but I zoomed in to 500% on my viewer and used a ruler against my screen and it's perfectly aligned now, and invisible to the reader! –  Ozzah Feb 10 '12 at 0:19
if it's desired that the last line fill the entire width, there are two alternate approaches: (1) use \break instead of the last double backslash; (2) treat the title as a paragraph, and end the text with \parfillskip0pt\par (the setting will go away at the end of the environment). –  barbara beeton Feb 10 '12 at 14:58

Use a tabular environment:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\mbox{\huge\bfseries
\begin{tabular}{@{}c@{}}
\toprule[.25mm]
This is my title, it is somewhat\\
long and split over two lines!\\
\bottomrule[.25mm]
\end{tabular}%
}
\end{document}


-

I am not sure I understand your first requirement, but you can use a \parbox to get the text to wrap as desired.

Here I have defined \MyTitleLength where you set the desired length. Since this is one time use you can just tweak it until you get the desired length. If it were to be used often I would use \widhtof{<text>} to compute the desired width. The same length us used to specify how long you want the rules to be.

You can use the center environment to get the centering. Here I have used the [showframe] option for the geometry package to show that it is centered.

A somewhat better result is obtained by centering the title text as well:

\parbox{\MyTitleLength}{\centering\huge\textbf{This is my title, it is somewhat long and split over two lines!}}\\[0.25cm]


\documentclass{article}
\begin{document}
\newlength{\MyTitleLength}%
\setlength{\MyTitleLength}{4.5in}%
%
\noindent\rule{\MyTitleLength}{0.25mm}\\[0.25cm]
\parbox{\MyTitleLength}{\huge\textbf{This is my title, it is somewhat long and split over two lines!}}\\[0.25cm]
\normalsize
\rule{\MyTitleLength}{0.25mm}
\end{document}

-