7

I think I am just too new to the LaTeX environment.

Do I just change the font size to fit the title into a single line? Then how do one change the font size of the title? Is there any other smart/automatic way of doing it?

Title means the title for the whole document, not chapter titles. Originally, I wanted to resize the fonts so that it can fit into one line, but then later I thought there was no issue for a 2-line title, so I kind of ignored the issue and kept on working. However, it would be still nice to know how to adjust the font size on the title.

Here is an example:

\documentclass[11pt]{article}

\title{\textbf{This Is A Very Long Title That Cannot Be Fitted Into One Line}}
\author{Author}
\date{}
\begin{document}

\maketitle

\end{document}

I am sorry I didn't update the question earlier. Thanks to everyone for the comments!

Snowfish
  • 173
  • 1
  • 1
  • 5

1 Answers1

5

I wouldn't consider what you're asking good practice, but you can redefine the \@maketitle macro (which is internally used by the article class to typeset the title), to put the title into a box and scale it to the appropriate width using the \resizebox macro from the graphics/graphicx package. Here's an example that might fit your needs:

\documentclass{article}

\usepackage{graphics}

\makeatletter
  \def\title@font{\Large\bfseries}
  \let\ltx@maketitle\@maketitle
  \def\@maketitle{\bgroup%
    \let\ltx@title\@title%
    \def\@title{\resizebox{\textwidth}{!}{%
      \mbox{\title@font\ltx@title}%
    }}%
    \ltx@maketitle%
  \egroup}
\makeatother

\title{A Title That's Either Very Long or Awfully Short}
\author{Me}

\begin{document}
\maketitle
\end{document}

Here, the title font properties are stored in \title@font, so you can change them at your own discretion. As an example, I set the title in a bold font. In particular, I would advise you to adjust the font size in the definition of \title@font, e.g. \Large, \Huge, \normalsize, ... , to match the proper optical font size as closely as possible, i.e. that the title has to be scaled by as small an amount as possible.

bencarabelli
  • 1,393
  • 7
  • 11
  • Sorry I am really noob to Latex. How to use \title@font? – Snowfish Apr 01 '13 at 21:24
  • @Snowfish observe the use of makeatletter and makeatother -- these commands turn the at symbol @ into a letter and an 'other' respectively. Normally, @ is a special character and not available for control sequences, but \makeatletter allows this, and \makeatother disallows it. (@ is often used for internal package commands.) See http://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do. – Sean Allred Apr 05 '13 at 08:12
  • If you're talking about actually using it, check out \renewcommand. – Sean Allred Apr 05 '13 at 08:18
  • @benwilfut Sorry man, I didn't realize your solution is so good until now. – Snowfish Aug 08 '14 at 18:05
  • @benwilfut How do we add subtitle in this case? I found this solution to work very well but it ignores \ to add a line break in the title and \subtitle does not work in article class. Thanks. – Anusha Jan 26 '17 at 13:34
  • @Anusha That's a bit tricky. First of all, you'd have to replace the 'mbox' in the code snippet with a 'parbox' to allow for line breaks in your title. However, a 'parbox' does not grow horizontally like an 'mbox'. Rather, you have to supply the width as an argument. You could define a new length, set it to the width of the first line of your title, and pass that to the 'parbox' containing your full title. I'll leave that as an exercise to the interested reader. ;P – bencarabelli Jan 30 '17 at 16:42