TransWikia.com

How to avoid small caps exceeding pre-defined document margins?

TeX - LaTeX Asked by Serendipity on December 30, 2020

When I use small caps in my document, they occasionally exceed the margins I have defined with the geometry package. The underlined part of the name "Lambrecht", which you can see in the picture below, is not supposed to appear outside the margin. The word should be split instead; is there something that can be done about this?

This image illustrates my problem with the name "Lambrecht".

Here is my preamble:

documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage[T1]{fontenc}
usepackage{amsmath}
usepackage{graphicx}
usepackage{layout}
usepackage{fancyhdr}
usepackage{gb4e}
noautomath
usepackage{booktabs}
usepackage{enumerate}
usepackage{verbatim}
usepackage{indentfirst}
usepackage{mathptmx}
usepackage[a4paper, top=20mm, bottom=20mm, left=25mm, right=35mm]{geometry}
usepackage{setspace}

And here is the source of the text passage that I’m concerned about:

 In contrast, the direct object in (10b) is syntactically independent from the main clause. Since 
  ``dislocated constituents are by definition optional sentence elements'' (textsc{Lambrecht} 2001: 
 1065), leaving out textit{This movie} in (10b) will not cause structural ill-formedness: 

I would appreciate any advice on how to solve this.

2 Answers

Microtype

It really helps to load the microtype-package. I took the liberty of shortening the example to make it truly minimal:

documentclass[
    a4paper,
    12pt
]{article}

%%% This you don't need anymore %%%
%%% usepackage[utf8]{inputenc} %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

usepackage[english]{babel}
usepackage[T1]{fontenc}

usepackage{mathptmx}
usepackage[a4paper, top=20mm, bottom=20mm, left=25mm, right=35mm]{geometry}
usepackage{microtype}

begin{document}

section{Introduction}

In contrast, the direct object in (10b) is syntactically independent from 
the main clause. Since ``dislocated constituents are by definition 
optional sentence elements'' (textsc{Lambrecht} 2001: 1065), leaving 
out textit{This movie} in (10b) will not cause structural ill-formedness: 

end{document}

-

If you still get overfull hboxes, you can try to assign hyphenation marks like so: textsc{Lam-b-recht} (depends on how this name has to be hyphenated).

Microtype saves the day

Correct answer by phil-elkabat on December 30, 2020

The problem is because LaTeX doesn't hyphenate the first word in some situations. (I didn't know this was the case for textsc.)

Here is a shorter example document with a smaller page:

documentclass[a5paper]{article}

begin{document}
Here is a shorter example.
Here is a shorter example.
Here is a shorter example.
Here is myyyyyy shorter example
(textsc{Lambrecht} 2001: 1065).

end{document}

This gives

enter image description here

with the word sticking out. One thing you can do is to add something invisible before it, like @moewe suggested in a comment. It would work with (hspace{0pt}textsc{Lambrecht} 2001: 1065).

That would be ugly to type in every place though. But it would be better to introduce a new command for writing these names anyway and use that instead of textsc. So in this version I define a command authnamefor writing author names which takes care of that in a single place.

documentclass[a5paper]{article}

newcommandauthname[1]{hspace{0pt}textsc{#1}}

begin{document}
Here is a shorter example.
Here is a shorter example.
Here is a shorter example.
Here is myyyyyy shorter example
(authname{Lambrecht} 2001: 1065).

end{document}

This gives a nicer result:

enter image description here

Next suggestion: Use Biblatex to handle your references. Then your LaTeX might look like this instead:

documentclass[a5paper]{article}
usepackage[style=authoryear]{biblatex}
addbibresource{sc.bib}

begin{document}
Here is a shorter example.
Here is a shorter example.
Here is a shorter example.
Here is myyyyyy shorter example
parencite[1065]{lambrecht}.

end{document}

This needs a file sc.bib which defines what the system should know about the lambrecht reference (like its title and the year 2001, etc.) The command parencite{lambrecht} inserts a parenthetical reference to the thing we have called "lambrecht" in that file. (Here it is used with an optional argument stating the page number as well.)

This wouldn't work as you want right out of the box, because using smallcaps is not the default and page references are written differently by default. So actually you would get

enter image description here

So you'd need to customize Biblatex a bit, something like this:

documentclass[a5paper]{article}
usepackage[style=authoryear]{biblatex}
addbibresource{sc.bib}

% Authors in small caps
renewcommand*{mkbibnamelast}[1]{textsc{#1}}
% Page numbers after colon
renewcommand{postnotedelim}{%
  iffieldpages{postnote}{addcolonspace}{addcommaspace}}
DeclareFieldFormat{postnote}{#1}

begin{document}
Here is a shorter example.
Here is a shorter example.
Here is a shorter example.
Here is myyyyyy shorter example
parencite[1065]{lambrecht}.

end{document}

That yields:

enter image description here

So now everything is good. So what happened with the hyphenation problem? Well, I guess Biblatex took care of that, so just by using the right tool instead of having to change fonts "manually" it just worked as expected.

Answered by pst on December 30, 2020

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