3

The following code produces and unwanted space. Why and how can it be avoided? A redefinition of the command or macros are invited.

\documentclass[letterpaper]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{enumitem,multicol,fullpage}
\usepackage{amsmath,amssymb}
\usepackage{tikz}

\newcounter{wsnumcnt}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\usetikzlibrary{fit,positioning}
\usetikzlibrary{calc,shapes}

\newcommand{\wssectsty}[2]{%
\setcounter{wsnumcnt}{#2}%
\gdef\wssecttitle{#1}%
\section*{\tikzmark{title}\color{Orange}\wssecttitle}%
\ifnum \thewsnumcnt<10%
    \tikz[remember picture,overlay]{%
    \node [
        left=42pt of title,
        anchor=base,
        fill=Orange, 
        rectangle,
        rounded corners,
        inner sep=5pt,
        outer sep=0pt,
        text=white,font=\bfseries\Large] 
    {\,PR \thewsnumcnt\phantom{1}};}%
\else%
    \tikz[remember picture,overlay]{%
    \node [
        left=42pt of title,
        anchor=base,
        fill=Orange, 
        rectangle, 
        rounded corners, 
        inner sep=5pt, 
        text=white,
        font=\bfseries\Large] 
    {\,PR \thewsnumcnt};}%
\fi%
}

\begin{document}
\wssectsty{Section}{1}
Objectives:
\begin{multicols}{3}
\small
\begin{itemize}[label=$\square$]
    \item Test 1
    \item Test 2
    \item Test 3
    \item Test 4
\end{itemize}
\end{multicols}
% Unwanted space here.
\wssectsty{Section}{1}
\begin{multicols}{3}
\small
\begin{itemize}[label=$\square$]
    \item Test 1
    \item Test 2
    \item Test 3
    \item Test 4
\end{itemize}
\end{multicols}
\section*{Section}
\begin{multicols}{3}
\small
\begin{itemize}[label=$\square$]
    \item Test 1
    \item Test 2
    \item Test 3
    \item Test 4
\end{itemize}
\end{multicols}
\end{document}

enter image description here

1 Answer 1

5

You can move the tikz node into the section heading so it aligns better.

enter image description here

\documentclass[letterpaper]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{enumitem,multicol,fullpage}
\usepackage{amsmath,amssymb}
\usepackage{tikz}

\newcounter{wsnumcnt}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\usetikzlibrary{fit,positioning}
\usetikzlibrary{calc,shapes}

\newcommand{\wssectsty}[2]{%
\setcounter{wsnumcnt}{#2}%
\gdef\wssecttitle{#1}%
\section*{\mbox{}\tikzmark{title}\color{Orange}\wssecttitle%
\ifnum \thewsnumcnt<10%
    \tikz[remember picture,overlay]{%
    \node [
        left=42pt of title,
        anchor=base,
        fill=Orange, 
        rectangle,
        rounded corners,
        inner sep=5pt,
        outer sep=0pt,
        text=white,font=\bfseries\Large] 
    {\,PR \thewsnumcnt\phantom{1}};}%
\else%
    \tikz[remember picture,overlay]{%
    \node [
        left=42pt of title,
        anchor=base,
        fill=Orange, 
        rectangle, 
        rounded corners, 
        inner sep=5pt, 
        text=white,
        font=\bfseries\Large] 
    {\,PR \thewsnumcnt};}%
\fi%
}}

\begin{document}
\wssectsty{Section}{1}
Objectives:
\begin{multicols}{3}
\small
\begin{itemize}[label=$\square$]
    \item Test 1
    \item Test 2
    \item Test 3
    \item Test 4
\end{itemize}
\end{multicols}
% Unwanted space here.
\wssectsty{Section}{1}
\begin{multicols}{3}
\small
\begin{itemize}[label=$\square$]
    \item Test 1
    \item Test 2
    \item Test 3
    \item Test 4
\end{itemize}
\end{multicols}
\section*{Section}
\begin{multicols}{3}
\small
\begin{itemize}[label=$\square$]
    \item Test 1
    \item Test 2
    \item Test 3
    \item Test 4
\end{itemize}
\end{multicols}
\end{document}

You must log in to answer this question.

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