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

1 Answers1

4

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

BambOo
  • 8,801
  • 2
  • 20
  • 47
  • 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}`.

    –  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? –  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. –  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. –  Sep 29 '19 at 18:33