- LaTeX Cookbook
- Stefan Kottwitz
- 442字
- 2021-07-09 21:25:00
Improving justification and hyphenation
Sometimes, you may get warnings like overfull \hbox
, or you may notice words hanging in the margin. This is a sign that LaTeX has had serious problems with justification. Now, we will take a look at how to improve that.
How to do it...
You can start with any document. We will optimize it with settings in the preamble. If you don't have one at hand, you can take one from the code package for this book, specifically for the first chapter, or download one at http://latex-cookbook.net. Let's proceed:
- Load the package
babel
with your document languages as options. Use the preferred language as the last option:\usepackage[ngerman,english]{babel}
- If you would like to use handy shortcuts of the
ngerman
package with English too, add the following lines of code:\useshorthands{"} \addto\extrasenglish{\languageshorthands{ngerman}}
- Load the
fontenc
package with theT1
option set:\usepackage[T1]{fontenc}
- Load the
microtype
package for improved micro-typography:\usepackage{microtype}
How it works...
With the babel
package, LaTeX uses the hyphenation patterns for the chosen language. Even for the English language it could be useful. As you have seen, the babel
package can additionally load the handy ngerman
shortcuts for hyphenation commands. You can find such shorthand commands in the babel
manual. You can open it by typing the texdoc babel
command in Command Prompt, or you can find it online at http://texdoc.net/pkg/babel.
The modern font encoding T1 improves the situation further. When TeX and LaTeX were introduced, fonts did not contain glyphs for accented characters. They were printed as two characters, one being the actual accent. That's bad for copying and pasting from the final PDF output. It also interfered with hyphenation.
The default encoding is called OT1, and covers 128 glyphs, which means that it encodes 128 characters. T1 provides 256 glyphs, so many accented characters are included. That's why T1 is recommended for Western European languages. There are further encodings for other languages, such as for Cyrillic and for Asian languages. If you would like to work with them, take a look at the fontenc
manual by typing the texdoc fontenc
command in Command Prompt, or you can read it online at http://texdoc.net/pkg/fontenc.
Finally, we let the microtype
package apply micro-typographic extensions. For example, the font size, even of single letters, might be scaled a little bit in favor of better full justification. You hardly can notice this with the naked eye, but you can see the effect of less hyphenation and better overall greyness of the text. Therefore, there should be smaller white gaps between words.
Furthermore, the microtype
package subtly adjusts punctuation at the margin for better optical alignment, instead of just mechanical justification.
- Implementing VMware Horizon 7(Second Edition)
- 零基礎(chǔ)搭建量化投資系統(tǒng):以Python為工具
- Learn Type:Driven Development
- Java高手真經(jīng)(高級編程卷):Java Web高級開發(fā)技術(shù)
- 大學(xué)計(jì)算機(jī)基礎(chǔ)(第2版)(微課版)
- C語言程序設(shè)計(jì)上機(jī)指導(dǎo)與習(xí)題解答(第2版)
- Instant Nancy Web Development
- Terraform:多云、混合云環(huán)境下實(shí)現(xiàn)基礎(chǔ)設(shè)施即代碼(第2版)
- 零基礎(chǔ)學(xué)C語言第2版
- Java圖像處理:基于OpenCV與JVM
- 大學(xué)計(jì)算機(jī)基礎(chǔ)
- 零基礎(chǔ)學(xué)C語言(升級版)
- 物聯(lián)網(wǎng)系統(tǒng)架構(gòu)設(shè)計(jì)與邊緣計(jì)算(原書第2版)
- Wearable:Tech Projects with the Raspberry Pi Zero
- Learning Java Lambdas