如何在嵌套的多列环境中获得更好的间距?

如何在嵌套的多列环境中获得更好的间距?

以下代码产生的输出内容间距很大。我的目标是编写一个包含多项选择题的练习。每个选项可能有一个图形。

在此处输入图片描述

红色箭头表示间距较大的部分。

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx}
\usepackage{multicol}
\columnsep=10pt
\usepackage{enumerate}

\def\question{%
Which is the correct statement about a quadratic function?}

\def\option{%
When $D<0$, the graph has 2 $x$-intercepts as shown in the figure below.

\begin{center}
        \includegraphics[width=0.8\linewidth]{foo}
\end{center}}%

\begin{document}
\begin{multicols}{2}[\section*{Exercise}]
\begin{enumerate}[1.]
% Question 1
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols} 
% Question 2
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols}
% Question 3
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols} 
% Question 4
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols}
\end{enumerate}
\end{multicols}
\end{document}

如何在嵌套multicols环境中获得更好的间距?我还注意到文本模式和数学模式下的间距都变得很奇怪。

如果这个问题不容易解决,还有其他方法可以实现我的目标吗,即创建一个具有与上面相同布局的多项选择练习?

答案1

您觉得这个怎么样?也许这是适合您的方法。它是使用picins-package 完成的。

在此处输入图片描述

在此处输入图片描述

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx}
\usepackage{multicol}
\columnsep=10pt
\usepackage{enumerate}
\usepackage{picins}

\def\question{%
Which is the correct statement about a quadratic function?}

\def\option{%
When $D<0$, the graph has 2 $x$-intercepts as shown in the figure below.\picskip{0}%
}

\def\fig{%
\parpic(3cm,3cm)[rd]{\includegraphics[height=2cm,width=2cm]{foo}}%
}%

\begin{document}
\begin{multicols}{2}[\section*{Exercise}]
\begin{enumerate}[1.]
% Question 1
\item \question
\begin{enumerate}
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
\end{enumerate}
\item \question
\begin{enumerate}
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
\end{enumerate}
\item \question
\begin{enumerate}
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
\end{enumerate}
\item \question
\begin{enumerate}
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
\end{enumerate}
\end{enumerate}
\end{multicols}
\end{document}

答案2

枚举环境和多列布局的嵌套总是有问题的。此外,代码很快就会变得混乱,难以使用。用户命令应该能够以如下方式运行:

\begin{...}[]
\question{}
\option{}
\option{}

\question{}
\option{}
\option{}
\end{...} 

并给你这个:

在此处输入图片描述

以下是 MWE 代码:

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx,xcolor}
\usepackage{multicol}
\columnsep=1.5em
\usepackage{pgfplots}
% better try a real example
\def\demoplot{%
\pgfplotsset{width=120pt,compat=1.3}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2 - x +4};
\end{axis}
\end{tikzpicture}
}
\parindent0pt
\makeatletter
% some counters 
\newcounter{ctr}\setcounter{ctr}{0}
\newcounter{ctrr}[ctr]\setcounter{ctrr}{0}
% to step counters and add some style
\def\inc{%
  \stepcounter{ctr}
  \bfseries\sffamily
  \color{blue}\thectr.
}
\def\Inc{%
  \stepcounter{ctrr}
  \color{purple}
  \bfseries\sffamily
  \alph{ctrr}.
}
% question 
\newcommand\question[1]{%
  \leavevmode
  \@hangfrom{\hbox to 15pt{\inc \hfill}}{%
     #1\par}%
}
% demo question
\newcommand{\demoquestion}{%
 \question{Which is the correct statement about 
      a quadratic function?}
}
% option
\newcommand\option[2]{%
  \vbox{\begin{minipage}{0.45\linewidth}
    \@hangfrom{\hbox to 15pt{\Inc}}{#1}
  \end{minipage}\hskip10pt\begin{minipage}{0.45\linewidth}
     \vspace*{5.5pt}%
     \centering%
     #2%\rule{80pt}{80pt}%#2
     \vspace{5.5pt}
  \end{minipage}\par}
}%
% option for demo
\newcommand{\demooption}{%
  \option{When $D<0$, the graph has 2 $x$- 
         intercepts as shown in the figure 
         below.}{\demoplot}
}
\makeatother

\begin{document}
\begin{multicols}{2}[\section*{\textcolor{purple}{EXERCISE}}]
    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

   \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption


    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

\end{multicols}
\end{document}

根据评论提出的替代计划:

在此处输入图片描述

以及新的 MWE:

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx,xcolor}
\usepackage{multicol}
\columnsep=1.5em
\usepackage{pgfplots}
\usepackage{enumerate}
\def\demoplot{%
\pgfplotsset{width=110pt,compat=1.3}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2 - x +4};
\end{axis}
\end{tikzpicture}
}
\parindent0pt
\makeatletter
\newcounter{ctr}\setcounter{ctr}{0}
\newcounter{ctrr}[ctr]\setcounter{ctrr}{0}

\def\inc{%
  \stepcounter{ctr}
  \bfseries\sffamily
  \color{blue}\thectr.
}
\def\Inc{%
  \stepcounter{ctrr}
  \color{purple}
  \bfseries\sffamily
  \alph{ctrr}.
}
% Demo question
\newcommand\question[1]{%
  \leavevmode
  \@hangfrom{\hbox to 15pt{\inc \hfill}}{%
     #1\par}%
}

\newcommand{\demoquestion}{%
 \question{Which is the correct statement about 
      a quadratic function?}
 \medskip
}
% Demo answer
\newcommand\option[2]{%
  \vbox{\hbox to \linewidth{\begin{minipage}[b]{0.45\linewidth}
    \@hangfrom{\hbox to 15pt{\Inc}}{#1}
    \end{minipage}\hfill%\hskip0.05\textwidth
    \begin{minipage}{0.45\linewidth}
     \vspace{-6pt} 
     \centering%
     \fbox{#2}%\rule{80pt}{80pt}%#2
  \end{minipage}\par}}
\smallskip
}%


\newcommand{\demooption}{%
  \option{When $D<0$, the graph has 2 $x$- 
         intercepts as shown in the figure 
         below.}{\demoplot}
}
\makeatother
\begin{document}
\begin{multicols}{2}[\section*{\textcolor{purple}{EXERCISE}}]
    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

   \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption


    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

\end{multicols}
\end{document}

添加包装图形的代码。

我们使用该wrapfig包将文本换行到图形中,同时避免使用列表。因此,我们所做的就是建立缩进和计数器。结果如下所示:

在此处输入图片描述

最后的 MWE 示例:

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx,xcolor}
\usepackage{multicol}
\columnsep=1.5em
\usepackage{pgfplots}
\usepackage{wrapfig}
\usepackage{ragged2e}
% better try a real example
\def\demoplot{%
\pgfplotsset{width=120pt,compat=1.3}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2 - x +4};
\end{axis}
\end{tikzpicture}
}
\parindent0pt
\makeatletter
% some counters 
\newcounter{ctr}\setcounter{ctr}{0}
\newcounter{ctrr}[ctr]\setcounter{ctrr}{0}
% to step counters and add some style
\def\inc{%
  \stepcounter{ctr}
  \bfseries\sffamily
  \color{blue}\thectr.
}
\def\Inc{%
  \stepcounter{ctrr}
  \color{purple}
  \bfseries\sffamily
  \alph{ctrr}.
}
% question 
\newcommand\question[1]{%
  \leavevmode
  \@hangfrom{\hbox to 15pt{\inc \hfill}}{%
     #1\par}%
}
% demo question
\newcommand{\demoquestion}{%
 \question{Which is the correct statement about 
      a quadratic function?}
}
% option
\newcommand\option[2]{%
  \vbox{\begin{minipage}{0.45\linewidth}
    \@hangfrom{\hbox to 15pt{\Inc}}{#1}
  \end{minipage}\hskip10pt\begin{minipage}{0.45\linewidth}
     \vspace*{5.5pt}%
     \centering%
     #2%\rule{80pt}{80pt}%#2
     \vspace{5.5pt}
  \end{minipage}\par}
}%
% option for demo
\newcommand{\demooption}{%
  \option{When $D<0$, the graph has 2 $x$- 
         intercepts as shown in the figure 
         below.}{\demoplot}
}

\newcommand\WrapFigure[1]{%
\begin{minipage}{0.9\linewidth}
\vspace{0pt} 
\setlength\intextsep{0pt}%
\setlength{\columnsep}{0pt}
\begin{wrapfigure}{r}[-10pt]{100pt}%
\demoplot %the image
\end{wrapfigure}
\hskip-20pt\@hangfrom{\hbox to 15pt{\Inc}}
\leftskip15pt
#1\par 
\end{minipage}
\vspace{\baselineskip}
}
\begin{document}
\begin{multicols*}{2}[\section*{\textcolor{purple}{EXERCISE}}]
\WrapFigure{%
This is a test of some sort to check it out. 
To see what is happening here. This is a test of some sort to check it out. To see what is happening here.\par
This is a test of some sort to check it out. 
To see what is happening here. This is a test of some sort to check it out. To see what is happening here.}
\medskip
\leftskip0pt
\demooption
\end{multicols*}
\end{document}

答案3

如果您用以下方式替换center环境\centering并使用,raggedcolumns您会获得更好的结果:

在此处输入图片描述

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx}
\usepackage{multicol}
\columnsep=10pt
\usepackage{enumerate}

\def\question{%
Which is the correct statement about a quadratic function?}

\def\option{%
When $D<0$, the graph has 2 $x$-intercepts as shown in the figure below.

\centering
        \includegraphics[width=0.8\linewidth]{foo}
}%

\begin{document}
\begin{multicols}{2}[\section*{Exercise}]\raggedcolumns
\begin{enumerate}[1.]
% Question 1
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols} 
% Question 2
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols}
% Question 3
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols} 
% Question 4
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols}
\end{enumerate}
\end{multicols}
\end{document}

相关内容