4

I am currently attempting to write my first Latex document and having some issues with it. There is a weird 3.33333pt at the top of the document, as can be seen in the attached image, and it will not go away despite whatever I do. My code is as follows:

\documentclass{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage{listings}
\usepackage{color}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{tabularx}

\lstset{
    frame=tb,
    language=Java,
    showstringspaces=false,
    columns=flexible,
    basicstyle={\small\ttfamily},
    numbers=none,
    numberstyle=\tiny\color{gray},
    keywordstyle=\color{blue},
    commentstyle=\color{dkgreen},
    stringstyle=\color{mauve},
    breaklines=true,
    breakatwhitespace=true,
    tabsize=3,
    moredelim=[il][\textcolor{pgrey}]{$$},
    moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%}
}

%\newcommand{\cmark}{\ding{51}\HS\HS\HS\HS}%

\begin{document}

\def\HS{\hspace{\fontdimen2\font}}\the\fontdimen2\font
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\title{Paper}
\author{
    Author One\\
    \texttt{author.one@email.com}
    \and
    Author Two\\
    \texttt{author.two@email.com}
}
\date{Docs version: 1.0.0\\\today}

\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{paper_title}}
\maketitle

\newpage

enter image description here

  • 2
    Welcome to TeX.SX! Why do you use \the\fontdimen2\font (which outputs something at the top)? – TeXnician Apr 5 '18 at 7:49
9

It comes from \the\fontdimen2\font placed immediately after \def\HS{\hspace{\fontdimen2\font}}, so just remove that.

You might also want to use \newcommand instead of \def. The latter will silently overwrite any existing macro, if the macro name (here \HS) was used before. Hence, if you're a bit unlucky/careless with the choice of macro name, you might end up breaking the document some way or another. \newcommand on the other hand checks if the macro is already defined, and throws an error if that is the case. (See also What is the difference between \def and \newcommand? for a lot of info about the difference between the two.)

Unrelated: I'd also move the colour definitions to the preamble, possibly along with \title/\author/\date (see Should I place \title, \author, \date in the preamble or after \begin{document}?).

\documentclass{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage{listings}
\usepackage{color}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{tabularx}

\lstset{
    frame=tb,
    language=Java,
    showstringspaces=false,
    columns=flexible,
    basicstyle={\small\ttfamily},
    numbers=none,
    numberstyle=\tiny\color{gray},
    keywordstyle=\color{blue},
    commentstyle=\color{dkgreen},
    stringstyle=\color{mauve},
    breaklines=true,
    breakatwhitespace=true,
    tabsize=3,
    moredelim=[il][\textcolor{pgrey}]{$$},
    moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%}
}

%\newcommand{\cmark}{\ding{51}\HS\HS\HS\HS}%

% \newcommand instead of \def here
\newcommand\HS{\hspace{\fontdimen2\font}}%\the\fontdimen2\font
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\title{Paper}
\author{
    Author One\\
    \texttt{author.one@email.com}
    \and
    Author Two\\
    \texttt{author.two@email.com}
}
\date{Docs version: 1.0.0\\\today}

\begin{document}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{paper_title}}
\maketitle

\newpage


\end{document}
  • 1
    Yes this works great! Thank you also for your feedback (: – Daniel Pacheco Apr 5 '18 at 8:20
  • 1
    I'd suggest \newcommand instead of \def. – egreg Apr 5 '18 at 8:54
  • @egreg Yes, good point, I've edited. – Torbjørn T. Apr 5 '18 at 9:07
  • @DanielPacheco See egreg's comment, and my edited answer. – Torbjørn T. Apr 5 '18 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.