0

My code creates a vertical line between the two columns, but I'm not sure how to make it dotted.

\usepackage[automark]{scrlayer-scrpage}
\usepackage[english]{babel}
\usepackage{blindtext}
\PassOptionsToPackage{svgnames}{xcolor}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{calc}
\usepackage[width = 18cm]{geometry}
\usepackage{enumitem}
\newcounter{question}
\newcounter{choice}
\setcounter{choice}{1}

\newcommand{\tikzhead}[1]{% \begin{tikzpicture}[remember picture,overlay] \node[yshift=-2.7cm, xshift=-1cm] at (current page.north west) {\begin{tikzpicture}[remember picture, overlay] \path[draw=none, fill=lightgray] (2,0) rectangle (\paperwidth,2cm); \end{tikzpicture} }; \end{tikzpicture}} \clearscrheadings \ihead{\tikzhead{\headmark}} \pagestyle{scrheadings}

\newenvironment{question}{% \stepcounter{question}% \noindent\colorbox{black}{\textcolor{white}{\makebox[1.5em][c]{\thequestion}}}% \colorbox{lightgray}{\phantom{\rule{\columnwidth-1.9em-\columnsep}{\heightof{1}}}}\par \begin{list}{}{% \setlength\itemindent{0pt}% \setlength\leftmargin{2em}% \setlength\rightmargin{1em}% \setlength\labelwidth{0pt}% \setlength\labelsep{0pt}}% \item[]}% {\end{list}}

\newenvironment{choices}{% \begin{list}{\Alph{choice})}{% \setlength\labelwidth{30pt}% \setlength\itemindent{0pt}% \setlength\leftmargin{2em}% \setlength\labelsep{10pt}% \usecounter{choice}}}% {\end{list}} \setlength\columnseprule{0.5pt}

\begin{document} \pagenumbering{gobble}

\twocolumn \begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\vspace{5cm}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\end{document}```

  • Welcome! I can't get this to compile without error. You haven't specified a class and you're using conflicting packages. This surely gives you errors when you try to compile it! – cfr Mar 28 '24 at 03:40
  • Also nesting tikzpictures is unsupported and very likely to cause weird bugs. – cfr Mar 28 '24 at 03:46

2 Answers2

0

This uses \AddToHook and tikzpagenodes.

\documentclass[twocolumn]{report}
\usepackage[automark]{scrlayer-scrpage}
\usepackage[english]{babel}
\usepackage{blindtext}
\PassOptionsToPackage{svgnames}{xcolor}
\usepackage{tikzpagenodes}% also loads tikz
\usepackage{xcolor}
%\usepackage{fancyhdr}
\usepackage{calc}
\usepackage[width = 18cm, headheight=2cm]{geometry}
\usepackage{enumitem}
\newcounter{question}
\newcounter{choice}
\setcounter{choice}{1}

\newsavebox{\headbox} \savebox{\headbox}{\begin{tikzpicture} \path[draw=none, fill=lightgray] (2,0) rectangle (\paperwidth,2cm); \end{tikzpicture}} %\geometry{headheight=\ht\headbox}

\pagestyle{scrheadings}% ???

\newenvironment{question}{% \stepcounter{question}% \noindent\colorbox{black}{\textcolor{white}{\makebox[1.5em][c]{\thequestion}}}% \colorbox{lightgray}{\phantom{\rule{\columnwidth-1.9em-\columnsep}{\heightof{1}}}}\par \begin{list}{}{% \setlength\itemindent{0pt}% \setlength\leftmargin{2em}% \setlength\rightmargin{1em}% \setlength\labelwidth{0pt}% \setlength\labelsep{0pt}}% \item[]}% {\end{list}}

\newenvironment{choices}{% \begin{list}{\Alph{choice})}{% \setlength\labelwidth{30pt}% \setlength\itemindent{0pt}% \setlength\leftmargin{2em}% \setlength\labelsep{10pt}% \usecounter{choice}}}% {\end{list}} %\setlength\columnseprule{0.5pt}

\AddToHook{shipout/background}{\begin{tikzpicture}[overlay,remember picture] \node at (current page header area.center) {\usebox\headbox}; \draw[dotted] (current page text area.north) -- (current page text area.south); \end{tikzpicture}}

\begin{document} \pagenumbering{gobble}

\twocolumn \begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\vspace{5cm}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
0

There's a lot of questionable code in your post and I've only done a very minimal cleanup. Regarding your actual question, it is probably easiest to set the column separator to 0pt in width and just add the dashed line with tikz, since you're using that anyway.

I've made the following assumptions:

  • that you're using scrarticle (since you're loading Koma packages);
  • that you're using A4 paper (ditto);
  • that you nonetheless want American hyphenation patterns (since you're explicitly loading this unless you configured your system differently);
  • that scrlayer-scrpage matters more to you than fancyhdr;
  • that you may or may not actually want geometry given everything else going on;
  • that you have no other reason for loading enumitem since you're not using it here;
  • that you are not filling your document with filler text for some reason and don't need blindtext.

Then the following produces a dashed rule as column separator, compiles without error and avoids nesting tikzpictures.

\documentclass[american,a4paper]{scrarticle}% or something?
\usepackage[automark]{scrlayer-scrpage}
\usepackage[english]{babel}% american, presumably
% \usepackage{blindtext} % unused, unnecessary
\PassOptionsToPackage{svgnames}{xcolor}
\usepackage{tikz}
\usepackage{tikzpagenodes}
% \usepackage{xcolor} % loaded by tikz
% \usepackage{fancyhdr} % incompatible with scrlayer-scrpage
\usepackage{calc}
\usepackage[width = 18cm]{geometry}% shouldn't be used with scrlayer-scrpage/koma classes if at all possible 
% \usepackage{enumitem} % unused
\newcounter{question}
\newcounter{choice}
\setcounter{choice}{1}

\newcommand{\tikzhead}[1]{% avoid nesting tikzpictures \begin{tikzpicture}[remember picture,overlay] \path[draw=none, fill=lightgray] ([yshift=-2.7cm, xshift=1cm]current page.north west) coordinate (lr) rectangle ++({\paperwidth-2cm},2cm); \draw [dashed] (current page text area.north) -- (current page text area.south); \end{tikzpicture}} \clearmainofpairofpagestyles % replace deprecated macro \ihead{\tikzhead{\headmark}} \pagestyle{scrheadings}

\newenvironment{question}{% \stepcounter{question}% \noindent\colorbox{black}{\textcolor{white}{\makebox[1.5em][c]{\thequestion}}}% \colorbox{lightgray}{\phantom{\rule{\columnwidth-1.9em-\columnsep}{\heightof{1}}}}\par \begin{list}{}{% \setlength\itemindent{0pt}% \setlength\leftmargin{2em}% \setlength\rightmargin{1em}% \setlength\labelwidth{0pt}% \setlength\labelsep{0pt}}% \item[]}% {\end{list}}

\newenvironment{choices}{% \begin{list}{\Alph{choice})}{% \setlength\labelwidth{30pt}% \setlength\itemindent{0pt}% \setlength\leftmargin{2em}% \setlength\labelsep{10pt}% \usecounter{choice}}}% {\end{list}} \setlength\columnseprule{0.5pt}

\begin{document} \pagenumbering{gobble}

\setlength{\columnseprule}{0pt}

\twocolumn \begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\vspace{5cm}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 3? \vspace{1.5cm} \end{question}

\begin{question} What is 1 + 4? \begin{choices} \item 1 \item 2 \item 5 \item 6 \end{choices} \vspace{0.5cm} \end{question}

\begin{question} What is 1 + 2? \vspace{1.5cm} \end{question}

\end{document}

Note that

  • enumitem would make your life easier, if you used it;
  • inserting explicit spacing should be a last resort and certainly not a frequent occurrence;
  • that inserting large amounts of rigid space tends to produce poor page-breaking;
  • I cannot currently produce images of output worth diddly-squat.

[My attempt to produce an image didn't even show the damn line --- never mind that it is now dashed.]

cfr
  • 198,882
  • Hi! Apologies for only responding now. Thank you so much for this. I'm very new to LaTeX and have to learn as I make things in real time. So everything is very messy and I'm only half-understanding things for now. I really appreciate your help! – lizochka Mar 30 '24 at 00:51