4

Suppose, we need to create a block for signatures for a contract consisting of 2 horizontal lines and names below them. main.tex:

\documentclass[12pt]{article}
\usepackage[a5paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=3cm,lmargin=2cm,rmargin=2cm}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\begin{document}
\noindent\makebox[.45\textwidth]{\hrulefill} \hfill\makebox[.45\textwidth]{\hrulefill}

\noindent\makebox[.45\textwidth][l]{Director 1} \hfill\makebox[.45\textwidth][l]{Director 2}
\end{document}

Output:

enter image description here Everything is fine. But when I move the code into a separate file signature.tex and put a reference to it into the main file:

\documentclass[12pt]{article}
\usepackage[a5paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=3cm,lmargin=2cm,rmargin=2cm}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\begin{document}
\input{signature.tex}
\end{document}

The name of the second person becomes shifted to the left:

enter image description here

What's wrong? How to fix? Using TeX Live 2017 on Windows XP.

2
  • 1
    Add a % in the last line of the input file: like ...{Director 2}%. Or alternatively add \unskip after the input line, like \input{signature.tex}\unskip.
    – Troy
    May 8, 2018 at 21:34
  • @Troy This fixed the issue. What was happening? Can you put an explanation with solution to the answer?
    – user4035
    May 8, 2018 at 21:45

1 Answer 1

7

Because \input is adding a space at the end of the input content, here the Director 1....Director 2 line.

You can avoid this in two ways:
Either add a % on the last line of your input file signature.tex, like:

\noindent\makebox[.45\textwidth]{\hrulefill} \hfill\makebox[.45\textwidth]{\hrulefill}

\noindent\makebox[.45\textwidth][l]{Director 1} \hfill\makebox[.45\textwidth][l]{Director 2}%

or add \unskip directly after the \input command:

\documentclass[12pt]{article}
\usepackage[a5paper,showframe]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=3cm,lmargin=2cm,rmargin=2cm}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\begin{document}
\input{signature.tex}\unskip
\end{document}

enter image description here
(frame added to show page margins)


Harald explains it well in a comment here:

It doesn't matter if the final line ends with a newline or not. The point is, TeX sees the file as consisting of a bunch of lines. As part of the tokenization process, a character whose code is the value of \endlinechar is inserted at the end of each line (except when the line ends with a comment or a control sequence).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .