使用 multicol 包和新命令的垂直间距问题

使用 multicol 包和新命令的垂直间距问题

以下代码会产生不必要的空格。为什么会产生空格?如何避免?请重新定义命令或宏。

\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}

在此处输入图片描述

答案1

您可以将 tikz 节点移动到部分标题中,以便更好地对齐。

在此处输入图片描述

\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}

相关内容