3

The two-column design works fine, but I encountered three problems:

  1. Every time I use a word that already has a hyphen (-) in it, LaTeX stops breaking the word with new hyphens to make it fit the column (so the word reaches into the next column).

  2. Every time I use $$ in a sentence, it can mess up by reaching out of the column as well

  3. Equations (\begin{equation}) doesn't break automatically either

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\usepackage[german]{babel}
\usepackage{cryptocode}
\usepackage{lipsum}

\begin{document}

\twocolumn
\pagebreak

\section{Diffie-Hellman-Schlüsselaustausch}
\lipsum[1-5]
\begin{equation}
{\displaystyle \mathrm {i} \hbar {\frac {\partial }{\partial t}}\psi (\mathbf {r} ,t)=\left(-{\frac {\hbar ^{2}}{2m}}\Delta +V(\mathbf {r} ,t)\right)\psi (\mathbf {r} ,t)},
\end{equation}

\lipsum[1]
\begin{equation}
F = \{F_{x} \in  F_{c} : (|S| > |C|) \cap 
(minPixels  < |S| < maxPixels) \cap 
(|S_{connected}| > |S| - \epsilon)
\}
\end{equation}

\end{document}

enter image description here

Mico
  • 506,678
  • Welcome to tex.stackexchange! Better to include a Minimum Working Example (MWE) so people can have a "feel" of the problem you are experiencing. It is also very likely that the problem could be easily traced if you provide the MWE. – Abdulhameed Feb 09 '20 at 02:16
  • 1
    About the section title, you can use some like \section{\parbox[t]{\linewidth}{Diffie-Hellman-Schlüsse\-laustausch}} About the equation, I think that is a duplicate of this question. – Fran Feb 09 '20 at 06:26

1 Answers1

5

First, some general points about your document setup:

  • No need to load amsfonts explicitly, as it's loaded automatically by amssymb.

  • Instead of

    \usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
    

    do just write

    \usepackage[margin=2cm]{geometry}
    

    unless you're a fan of code clutter.

  • Unless you must adhere to an explicit requirement to employ pre-1995 German spelling and hyphenation rules, do replace

    \usepackage[german]{babel}
    

    with

    \usepackage[ngerman]{babel} % note the 'n' in 'ngerman'
    

Next, you may not be aware of the fact that LaTeX and TeX do not line-break words if they are parts of compound hyphenated words. Thus, "Schlüsselaustausch" doesn't get hyphenated and line-broken if it occurs in the [to me atrocious-looking!] "Diffie-Hellman-Schlüsselaustausch" string. I suggest you add the instructions

\usepackage{sectsty}
\allsectionsfont{\raggedright}

to the preamble. This will force LaTeX to insert a line break immediately before "Schlüsselaustausch". Adding these two instructions is probably a good idea anyway, given that (a) your document is typeset in two-column mode and (b) hyphenation of words in sectioning headers is often frowned upon as running against "fine typography". I don't personally share the view that one should never hyphenate words in a sectioning header, but I'm aware that quite a few people do hold this view. When in doubt, it's better not to get involved in a debate with them...


I'm not sure I know how to interpret your sentence that "Every time I use $$ in a sentence, it can mess up by reaching out of the column as well". For sure, $$ is used in PlainTeX (not so much in LaTeX) to initiate and terminate display-math mode. If, instead, you're referring to inline-math mode, i.e., if you meant to write $...$, the simple rule is that TeX can insert line breaks at some, fairly restrictive locations inside an inline formula, but not at arbitrary locations.

Since you didn't provide an example of an inline math formula which you need to get line-broken, it's not possible to give more specific advice on how to proceed. A general piece of advice, though: do keep all inline-math expressions short and simple. You readers will appreciate the gesture, and you'll run into far fewer pesky line-breaking issues.


About line-breaking in equation environments: I'm not sure what the basis may be for your view that LaTeX performs (or should perform?) line-breaking on the material in such environments. In fact, the opposite is the case. Hence, if you want line breaks in a long displayed equation, you have to supply them yourself, and you have to use a display math environment other than equation. (Well, there is a package called breqn that can perform automatic line-breaking. However, its results often require further, manual tweaking.)

For the equation at hand, I suggest you employ a multline environment (provided by the amsmath package) and supply two break points (indicated by \\). For the formula at hand, inserting breakpoints immediately before the \cap directives looks like a sensible way to proceed. To help the reader's eye "parse" the equation quickly, you may also apply some manual sizing of the curly braces and round parentheses; see the screenshot below for a case that uses \Bigl/\Bigr as well as \bigl/\bigr.

Two additional comments while on the subject of math typesetting. First, you seem to have a fondness for encasing subformulas in curly braces. The extra curly braces achieve nothing but create code clutter. Do try to wean yourself off this habit. Second, if entire natural-language words appear in a formula, encase them in either \mathrm or mathit statements; otherwise, LaTeX will process these words as if they're formulas in their own right -- frequently with undesirable outcomes. For the second equation, this concerns the words "minPixels", "maxPixels", and "connected".


enter image description here

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc} % not needed unless your TeX distribution is quite old
\usepackage[T1]{fontenc}
\usepackage{amsmath}
%%\usepackage{amsfonts} %% not needed
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage[margin=2cm]{geometry}
\usepackage[ngerman]{babel} % ngerman, not german, right?
\usepackage{cryptocode}
\usepackage{lipsum}

\usepackage{sectsty}
\allsectionsfont{\raggedright}

\begin{document}

\twocolumn
%%\pagebreak % unnecessary

\section{Diffie-Hellman-Schlüsselaustausch}

\dots
\begin{equation}
\mathrm{i} \hbar \frac{\partial }{\partial t} \psi(\mathbf{r},t) =
\biggl( -\frac{\hbar ^{2}}{2m} \Delta 
+V(\mathbf{r},t) \biggr) \psi(\mathbf{r},t) \,,
\end{equation}
\dots
\begin{multline} 
F = \Bigl\{ F_{x} \in  F_{c} : \bigl( |S| > |C| \bigr) \\
  \cap \bigl( \mathrm{minPixels}  < |S| < \mathrm{maxPixels} \bigr) \\
  \cap \bigl( |S_{\mathrm{connected}}| > |S| - \epsilon \bigr) \Bigr\}
\end{multline}

\end{document}
Mico
  • 506,678
  • Thank you. But your solution only helps me for all sections - but not for the plain text? – Klara M. Lund Feb 09 '20 at 13:15
  • @KlaraM.Lund - I wrote earlier, "LaTeX and TeX do not line-break words if they are parts of compound hyphenated words"; an example of such a work is, of course, Diffie-Hellman-Schlüsselaustausch. The babel package, when loaded with the ngerman option, provides the following work-around: replace - with "=. E.g., if you replace Diffie-Hellman-Schlüsselaustausch with Diffie-Hellman"=Schlüsselaustausch, LaTeX will be able to hyphenate Schlüsselaustausch as needed. (I wouldn't permit hyphenation of the proper names "Diffie" and "Hellman"; hence, do keep the first instance of -.) – Mico Feb 09 '20 at 13:43