TransWikia.com

How to extend (or kern) a subtitle to the text width?

TeX - LaTeX Asked on July 20, 2021

I have a subtitle that is almost as large as the text width. For aesthetical purposes, I would like to strech it a bit so it covers the whole text width, and be more harmonious with the picture below the subtitle. How can I achieve this trick?

Here’s a code that show the subtitle:

documentclass[letterpaper]{book}
usepackage[T1]{fontenc}
usepackage{microtype}
usepackage{lmodern}
usepackage[utf8]{inputenc}
usepackage[french]{babel}
usepackage{anysize}
marginsize{1.5in}{1in}{0.5in}{0.5in}
usepackage[x11names]{xcolor}
definecolor{backgroundcolor}{RGB}{180, 180, 160}
definecolor{subtitle}{RGB}{240, 240, 200}
usepackage{graphicx}
usepackage{here}
usepackage{afterpage}

usepackage{librebaskerville}
usepackage{tikz}
usetikzlibrary{calc}

newcommand*{maintitle}{begingroup

    pagecolor{backgroundcolor}

    centering

    flushleft{
        textcolor{subtitle}{Hugetextsf{La théorie classique des champs relativistes}}
    }

    begin{figure}[H]
        center
        includegraphics[width=1textwidth]{example-image}
    end{figure}

endgroup}

begin{document}

begin{titlepage}

% FRAME AROUND PAGE :
    begin{tikzpicture}[remember picture, overlay]
        draw[line width = 1in,color = white] ($(current page.north west) + (0.25in,0.25in)$) rectangle ($(current page.south east) + (0.25in,-0.25in)$);
        draw[line width = 0.25pt,color = black] ($(current page.north west) + (0.75in,-0.25in)$) rectangle ($(current page.south east) + (-0.25in,0.25in)$);
        draw[line width = 1pt,color = white] ($(current page.north west) + (1in,-0.5in)$) rectangle ($(current page.south east) + (-0.5in,0.5in)$);
    end{tikzpicture}

    maintitle
end{titlepage}

end{document}

Preview of what this code is doing:

enter image description here

All I need here is to extend or stretch the subtitle so it has a lenght equal to the textwidth. The space to the right should be the same as the space on the left side (which should stay the same).


EDIT: I’ve updated the code above. Maybe I wasn’t clear about how much stretching I wanted. I certainly don’t want the subtitle to be stretched right to the vertical lines on both sides. The subtitle in flushed left, and there’s a nice space between the left line and the beginning of the subtitle. This should stay fixed. But then, I need to stretch the right part just a bit, to get a subtitle of the same size as the picture below it.

One Answer

I'd avoid this.

Anyway, here's how you can do it. Note that accented characters and possible ligatures have to be braced.

I made some adjustments:

  1. anysize is much less powerful than geometry and has not been maintained in 26 years;
  2. the here package is obsolete; use float instead, but never use [H];
  3. the minipage doesn't seem needed, particularly with width 2textwidth;
  4. to set something larger than the text width, use makebox;
  5. I added some space at either size so the text doesn't touch the frame lines.
documentclass[letterpaper]{book}
usepackage[inner=1.5in,outer=1in,top=0.5in,bottom=0.5in]{geometry}
%usepackage[utf8]{inputenc} % not needed with recent versions of LaTeX
usepackage[T1]{fontenc}
usepackage[french]{babel}
usepackage{microtype}
usepackage{graphicx}
usepackage[x11names]{xcolor}
definecolor{backgroundcolor}{RGB}{180, 180, 160}
definecolor{subtitle}{RGB}{240, 240, 200}

usepackage{lmodern} % for sans serif
usepackage{librebaskerville}
usepackage{tikz}
usetikzlibrary{calc}

usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{expandto}{mm}
 {
  seq_set_split:Nnn l_tmpa_seq { ~ } { #2 }
  seq_set_map:NNn l_tmpb_seq l_tmpa_seq { cham_expand_word:n { ##1 } }
  leavevmode
  hbox_to_wd:nn { #1 }
   {
    hspace{3pt}
    seq_use:Nn l_tmpb_seq { hspace{0.33333em plus 1fil} }
    hspace{3pt}
   }
 }
cs_new_protected:Nn cham_expand_word:n
 {
  seq_set_split:Nnn l_tmpa_seq { } { #1 }
  seq_use:Nn l_tmpa_seq { hspace{0pt plus 0.6fil} }
 }
ExplSyntaxOff

newcommand*{maintitle}{%
  begingroup
  pagecolor{backgroundcolor}
  centering
  makebox[textwidth]{%
    color{subtitle}Hugesffamily
    expandto{textwidth+1in}{La th{é}orie classique des champs relativistes}%
  }%
  endgroup
}

begin{document}

begin{titlepage}

% FRAME AROUND PAGE :
begin{tikzpicture}[remember picture, overlay]
  draw[line width = 1in,color = white] ($(current page.north west) + (0.25in,0.25in)$) rectangle ($(current page.south east) + (0.25in,-0.25in)$);
  draw[line width = 0.25pt,color = black] ($(current page.north west) + (0.75in,-0.25in)$) rectangle ($(current page.south east) + (-0.25in,0.25in)$);
  draw[line width = 1pt,color = white] ($(current page.north west) + (1in,-0.5in)$) rectangle ($(current page.south east) + (-0.5in,0.5in)$);
end{tikzpicture}

    maintitle

end{titlepage}

end{document}

enter image description here

Look at the picture and see why I started with ‘I'd avoid this’. ;-)

If the title should use the text width:

documentclass[letterpaper]{book}
usepackage[inner=1.5in,outer=1in,top=0.5in,bottom=0.5in]{geometry}
%usepackage[utf8]{inputenc} % not needed with recent versions of LaTeX
usepackage[T1]{fontenc}
usepackage[french]{babel}
usepackage{microtype}
usepackage{graphicx}
usepackage[x11names]{xcolor}
definecolor{backgroundcolor}{RGB}{180, 180, 160}
definecolor{subtitle}{RGB}{240, 240, 200}

usepackage{lmodern} % for sans serif
usepackage{librebaskerville}
usepackage{tikz}
usetikzlibrary{calc}

usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{expandto}{O{0pt}mm}
 {
  seq_set_split:Nnn l_tmpa_seq { ~ } { #3 }
  seq_set_map:NNn l_tmpb_seq l_tmpa_seq { cham_expand_word:n { ##1 } }
  leavevmode
  hbox_to_wd:nn { #2 }
   {
    hspace{#1}
    seq_use:Nn l_tmpb_seq { hspace{0.33333em plus 1fil} }
    hspace{#1}
   }
 }
cs_new_protected:Nn cham_expand_word:n
 {
  seq_set_split:Nnn l_tmpa_seq { } { #1 }
  seq_use:Nn l_tmpa_seq { hspace{0pt plus 0.6fil} }
 }
ExplSyntaxOff

newcommand*{maintitle}{%
  begingroup
  pagecolor{backgroundcolor}
  centering
  makebox[textwidth]{%
    color{subtitle}Hugesffamily
    expandto{textwidth}{La th{é}orie classique des champs relativistes}%
  }
  includegraphics[width=textwidth]{example-image}%
  endgroup
}

begin{document}

begin{titlepage}

% FRAME AROUND PAGE :
begin{tikzpicture}[remember picture, overlay]
  draw[line width = 1in,color = white] ($(current page.north west) + (0.25in,0.25in)$) rectangle ($(current page.south east) + (0.25in,-0.25in)$);
  draw[line width = 0.25pt,color = black] ($(current page.north west) + (0.75in,-0.25in)$) rectangle ($(current page.south east) + (-0.25in,0.25in)$);
  draw[line width = 1pt,color = white] ($(current page.north west) + (1in,-0.5in)$) rectangle ($(current page.south east) + (-0.5in,0.5in)$);
end{tikzpicture}

    maintitle

end{titlepage}

end{document}

enter image description here

About your edit:

  • flushleft is not a user level command and it takes no argument;

  • there is no need to use figure around an image.

I transformed the padding on either side into an optional argument to expandto just in case you need it elsewhere.

Answered by egreg on July 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP