0

I've managed to number a series of lines in a page (as in an exam sheet) using tikz, but it feels awkward and somewhat sketchy. Is there any way to improve it or make it "cleaner" (with or without other packages)?

\documentclass[12pt,oneside]{article}
\usepackage[a4paper,margin=2cm]{geometry}%showframe
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[sfdefault,lf]{FiraSans}
\usepackage{lineno}

\newcounter{linha}
\newcommand{\linha}{\stepcounter{linha}\arabic{linha}}

\begin{document}

\begin{tikzpicture}
\foreach \x in {1,1.7,...,26}
\draw (0,\x) -- (16,\x);
\end{tikzpicture}

\begin{tikzpicture}[overlay]
\foreach \x in {25.25,24.55,...,0.3}
%\foreach \y in {1,...,26}
\node at (-0.8,\x) {\linha};
\end{tikzpicture}




\end{document}


\documentclass[border={5pt}]{standalone}
\usepackage{tikz}
\begin{document}



\begin{tikzpicture}[remember picture,overlay]
\foreach \x in {1,...,5}
\draw[line width=\x mm] (0,\x) -- (2,\x);
\end{tikzpicture}

\end{document}

enter image description here

  • Hmm, if you don't mind, what is your purpose here ? – BambOo Sep 29 '19 at 12:57
  • @BambOo, simple exam answer sheet with numbered lines. – Joseph Sep 29 '19 at 12:57
  • Does the numbering stand for answer numbering ? – BambOo Sep 29 '19 at 13:01
3

You could use this approach, based on this answer.

\documentclass[12pt,oneside]{article}
\usepackage[a4paper,margin=2cm]{geometry}%showframe
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{lineno}
\usepackage{pgffor}

\begin{document}
\linenumbers
\foreach \nline in {1,...,21}{
\noindent\rule{\linewidth}{0.4pt}%
}

\end{document}

enter image description here

  • 2
    You could do with less packages: \documentclass[12pt,oneside]{article} \usepackage{lineno} \newcounter{nline} \begin{document} \linenumbers\setcounter{nline}{0}\loop% \stepcounter{nline}\noindent\rule{\linewidth}{0.4pt} \ifnum\value{nline}<21\repeat \end{document}. – Schrödinger's cat Sep 29 '19 at 15:34
  • This is great. I have not found the \nline command anywhere in the tikz documentation. Where does it come from? – Joseph Sep 29 '19 at 16:29
  • @Joseph This is just the loop variable. You may replace it by whatever macro you like, e.g. \CuteFurryRodent will also work. – Schrödinger's cat Sep 29 '19 at 16:43
  • @Schrödinger'scat, nice to know. I didn't know a random undefined variable was somehow needed if it isn't called back later. By the way, \CuteFurryRodent sounds nice. – Joseph Sep 29 '19 at 18:33

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.