0

I'm beginning to write my personal *.sty file and I would like it to be able to automatically wrap the document title in case it's too long (I'm not sure whether "wrap" is the correct term: I mean to automatically display it on more than one line if need be).

My *.sty file looks like this (I'm not a TeX\LaTeX expert, so it's based on another *.sty file with some slight modifications):

\NeedsTeXFormat{LaTeX2e}

% Some code
\newcommand{\@titolo}{Senza Titolo}
\newcommand{\titolo}[1]{\renewcommand{\@titolo}{#1}}
\renewcommand\maketitle{\begin{titlepage}
% Some code

{\vfil
    \begin{LARGE}
    {\bf\renewcommand{\\}{\cr}
    \halign{\hbox to\textwidth{\strut\hfil##\hfil}\cr
    \@titolo\cr}}
\end{LARGE}}

% Some code
\end{titlepage}
\endinput

So, the question is: is there a way to automatically display the title on more than one line? I've tried by inserting \@titolo inside a \minipage but wasn't able to succeed. Any kind of help or hint is appreciated.

DavideM
  • 181
  • 2
    Welcome, \bf is obsolete for more than twenty years. Redefining \\ doesn't seem like a good idea either. LARGE is not an environment. hboxes cannot be broken in differente lines. Personally, i would not base my package on that package you are using. – Johannes_B Sep 10 '16 at 08:20
  • 2
    where did the code you start from come from? \vfil does nothing in that position, \bf shouldn't be used in latex (it's not defined by default) and using a primitive \halign rather than a latex construct such as tabular will have weird side effects. The title would wrap automatically if you did not put it in the halign. – David Carlisle Sep 10 '16 at 08:20
  • @DavidCarlisle, I've rewritten the code using a tabular environment and it worked out just fine. The code dated back to 2006, but I didn't expect it to be obsolete, thanks for letting me know. @Johannes_B, I'll definetly take a look at that link in the future. – DavideM Sep 10 '16 at 14:19

1 Answers1

1

Seems silly to answer to my own question, but as a reference I'll write a working solution that I was able to write thanks to the help received through the comments and some research on LaTeX book by wikibooks.org. I simply substituted the {\vfil ...} part with a \tabular environment:

\begin{tabular}{>{\centering}>{\bfseries}>{\huge}p{1\textwidth}<{\centering}}
    \@titolo
\end{tabular}

The title (\@titolo) wraps just fine and it is bold.

DavideM
  • 181
  • Please have a look at https://en.wikibooks.org/wiki/LaTeX/Title_Creation#A_title_to_be_re-used_multiple_times. There is absolutely no need to use a tabular environment with a parbox inside. All this gets you is a warning if you are in the wrong place. – Johannes_B Sep 10 '16 at 20:32
  • That gives me the possibility of choosing the width of the title, doesn't it? – DavideM Sep 11 '16 at 08:26
  • Yes, it does. Using the parbox. The tabular isn't needed at all. If the linewidth is equal to textwidth, the parbox isn't needed as well. – Johannes_B Sep 11 '16 at 08:29