![书籍类的一个奇怪的输出](https://linux22.com/image/386114/%E4%B9%A6%E7%B1%8D%E7%B1%BB%E7%9A%84%E4%B8%80%E4%B8%AA%E5%A5%87%E6%80%AA%E7%9A%84%E8%BE%93%E5%87%BA.png)
我正在使用 book 类编写一本多项选择题书。main.tex 如下。
\documentclass[12pt,a4paper]{book}
\usepackage{amsmath,amsthm}
\usepackage{ifthen,amsfonts,amssymb,dsfont}
\usepackage{etoolbox,multicol}
\documentclass[12pt,a4paper]{book}
\usepackage{amsmath,amsthm}
\usepackage{ifthen,amsfonts,amssymb,dsfont}
\usepackage{etoolbox,multicol}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{enumitem,kantlipsum}
\usepackage[dvips]{graphicx,color}
\usepackage{verbatim, pstricks,ulem}
\usepackage{syntonly}
\newcommand{\newmatrix}[2]{\left(\begin{array}{#1} #2\end{array}\right)}
\newbox\allanswerkeys
\setbox\allanswerkeys=\vbox{}
\newenvironment{answerkey}{%
\global\setbox\allanswerkeys=\vbox\bgroup
\unvbox\allanswerkeys
}%
{%
\bigbreak
\egroup
}
\newcommand{\showallanswerkeys}{\par\unvbox\allanswerkeys}
\newcommand*{\getanswerkeys}[6]{%
\item[\theenumi.]\begin{answerkey}(#5)\end{answerkey}
}
\newbox\allanswers
\setbox\allanswers=\vbox{}
\newenvironment{answer}{%
\global\setbox\allanswers=\vbox\bgroup
\unvbox\allanswers
}%
{%
\bigbreak
\egroup
}
\newcommand{\showallanswers}{\par\unvbox\allanswers}
\newcommand*{\getanswer}[6]{%
\ifthenelse{\equal{#6}{}}{}{
\item[\theenumi.]\begin{answer}(#5)~#6\end{answer}
}}
\setlength\parindent{0pt}
\newcommand{\fourch}[6]{
\par
\begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
(a)~#1 & (b)~#2 & (c)~#3 & (d)~#4
\end{tabular}
\getanswer{#1}{#2}{#3}{#4}{#5}{#6}
\getanswerkeys{#1}{#2}{#3}{#4}{#5}{#6}
}
\newcommand{\twoch}[6]{
\par
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(a)~#1 & (b)~#2
\end{tabular}
\par%\vspace{4pt}
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(c)~#3 & (d)~#4
\end{tabular}
\getanswer{#1}{#2}{#3}{#4}{#5}{#6}
\getanswerkeys{#1}{#2}{#3}{#4}{#5}{#6}
}
\newcommand{\onech}[6]{
%\par
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(a) & #1
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(b) & #2
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(c) & #3
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(d) & #4
\end{tabular}
\getanswer{#1}{#2}{#3}{#4}{#5}{#6}
\getanswerkeys{#1}{#2}{#3}{#4}{#5}{#6}
}
\newlength\widthcha
\newlength\widthchb
\newlength\widthchc
\newlength\widthchd
\newlength\widthch
\newlength\tabmaxwidth
\setlength\tabmaxwidth{0.96\textwidth}
\newlength\fourthtabwidth
\setlength\fourthtabwidth{0.25\textwidth}
\newlength\halftabwidth
\setlength\halftabwidth{0.5\textwidth}
\newcommand{\choice}[6]{%
\settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}%
\settowidth\widthchb{BM.#2}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
\settowidth\widthchb{CM.#3}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch} {\widthchb}\fi%
\settowidth\widthchb{DM.#4}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch} {\widthchb}\fi%
\ifdim\widthch>\halftabwidth
\onech{#1}{#2}{#3}{#4}{#5}{#6}
\else\ifdim\widthch<\halftabwidth
\ifdim\widthch>\fourthtabwidth
\twoch{#1}{#2}{#3}{#4}{#5}{#6}
\else
\fourch{#1}{#2}{#3}{#4}{#5}{#6}
\fi\fi\fi}
\newcommand{\mcq}[8]{
\item #2
\choice{#3}{#4}{#5}{#6}{#7}{#8}
}
\def\databaseone{
\mcq{245}{Let $A$ be a symmetric matrix of order $n$ and $B$ be a skew- symmetric matrix of order $n$. Then which one of the following is a skew-symmetric matrix?}{$A^{2}$}{$B^{2}$}{$AB+BA$}{$AB-BA$}{c}{}{}
\mcq{248}{A square matrix is a diagonal matrix if and only if it is}{upper triangular}{lower triangular}{both upper triangular and lower triangular}{none of these}{c}{}{}
\mcq{249}{Let $A$ be a non-singular matrix of order $3$. Then the rank of matrix $A^{2018}$ is}{$1$}{$2$}{$3$}{$9$}{c}{Note that $A^{2018}$ is a non-singular matrix of order $3$. Hence rank $(A^{2018})=3$.}{}
\mcq{250}{If $A=\newmatrix{ccc}{0 & 1 & 0\\0 & 0 & 1\\1 & 0 & 0}$, then rank of the matrix $A+A^{2}+A^{3}$ is}{$1$}{$2$}{$3$}{none of these}{a}{Note that $A+A^{2}+A^{3}=\protect\newmatrix{ccc}{1 & 1 & 1\\1 & 1 & 1\\1 & 1 & 1}$. Hence rank $(A+A^{2}+A^{3})=1$}{}
}
\begin{document}
\chapter{One}
\begin{enumerate}
\databaseone
\end{enumerate}
\bigskip
\Huge{Answer Key:}
\bigskip
\begin{center}
\begin{multicols}{6}
\showallanswerkeys
\end{multicols}
\end{center}
\bigskip
\Huge{Hint/Explanation of Selected Problems:}
\bigskip\bigskip
\showallanswers
\chapter{Two}
\begin{enumerate}
\databaseone
\end{enumerate}
\bigskip
\Huge{Answer Key:}
\bigskip
\begin{center}
\begin{multicols}{6}
\showallanswerkeys
\end{multicols}
\end{center}
\bigskip
\Huge{Hint/Explanation of Selected Problems:}
\bigskip\bigskip
\showallanswers
\end{document}
当我在 overleaf 中运行此代码时,得到了以下奇怪的输出。
第二章的输出与第一章不同。
请帮我。
提前谢谢了。
答案1
\documentclass[12pt,a4paper]{book}
\usepackage{amsmath,amsthm}
\usepackage{ifthen,amsfonts,amssymb,dsfont}
\usepackage{etoolbox,multicol}
%%NO!!! two \documentclass \documentclass[12pt,a4paper]{book}
%% NO already loaded \usepackage{amsmath,amsthm}
%% NO already loaded \usepackage{ifthen,amsfonts,amssymb,dsfont}
%% NO already loaded \usepackage{etoolbox,multicol}
\usepackage[english]{babel}
% not in areal document \usepackage{blindtext}
\usepackage{geometry}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{enumitem,
% not in a real documentkantlipsum
}
\usepackage[
% NO dvips
]{graphicx,color}
\usepackage{verbatim, pstricks,ulem}
%NO! This disables almost all of latex if you use it \usepackage{syntonly}
% No use pmatrix from amsmath \newcommand{\newmatrix}[2]{\left(\begin{array}{#1} #2\end{array}\right)}
\newbox\allanswerkeys
\setbox\allanswerkeys=\vbox{}
\newenvironment{answerkey}{%
\global\setbox\allanswerkeys=\vbox\bgroup
\unvbox\allanswerkeys
}%
{%
\bigbreak
\egroup
}
\newcommand{\showallanswerkeys}{\par\unvbox\allanswerkeys}
\newcommand*{\getanswerkeys}[6]{%
\item[\theenumi.]\begin{answerkey}(#5)\end{answerkey}
}
\newbox\allanswers
\setbox\allanswers=\vbox{}
\newenvironment{answer}{%
% OK but this is not colour safe, don't use colour in this environment
\global\setbox\allanswers=\vbox\bgroup
\unvbox\allanswers
}%
{%
\bigbreak
\egroup
}
\newcommand{\showallanswers}{\par\unvbox\allanswers}
\newcommand*{\getanswer}[6]{%
\ifthenelse{\equal{#6}{}}{}{
\item[\theenumi.]\begin{answer}(#5)~#6\end{answer}
}}
\setlength\parindent{0pt}
\newcommand{\fourch}[6]{
\par
\begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
(a)~#1 & (b)~#2 & (c)~#3 & (d)~#4
\end{tabular}
\getanswer{#1}{#2}{#3}{#4}{#5}{#6}
\getanswerkeys{#1}{#2}{#3}{#4}{#5}{#6}
}
\newcommand{\twoch}[6]{
\par
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(a)~#1 & (b)~#2
\end{tabular}
\par%\vspace{4pt}
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(c)~#3 & (d)~#4
\end{tabular}
\getanswer{#1}{#2}{#3}{#4}{#5}{#6}
\getanswerkeys{#1}{#2}{#3}{#4}{#5}{#6}
}
\newcommand{\onech}[6]{
%\par
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(a) & #1
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(b) & #2
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(c) & #3
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(d) & #4
\end{tabular}
\getanswer{#1}{#2}{#3}{#4}{#5}{#6}
\getanswerkeys{#1}{#2}{#3}{#4}{#5}{#6}
}
\newlength\widthcha
\newlength\widthchb
\newlength\widthchc
\newlength\widthchd
\newlength\widthch
\newlength\tabmaxwidth
\setlength\tabmaxwidth{0.96\textwidth}
\newlength\fourthtabwidth
\setlength\fourthtabwidth{0.25\textwidth}
\newlength\halftabwidth
\setlength\halftabwidth{0.5\textwidth}
\newcommand{\choice}[6]{%
\settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}%
\settowidth\widthchb{BM.#2}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
\settowidth\widthchb{CM.#3}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch} {\widthchb}\fi%
\settowidth\widthchb{DM.#4}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch} {\widthchb}\fi%
\ifdim\widthch>\halftabwidth
\onech{#1}{#2}{#3}{#4}{#5}{#6}
\else\ifdim\widthch<\halftabwidth
\ifdim\widthch>\fourthtabwidth
\twoch{#1}{#2}{#3}{#4}{#5}{#6}
\else
\fourch{#1}{#2}{#3}{#4}{#5}{#6}
\fi\fi\fi}
\newcommand{\mcq}[8]{
\item #2
\choice{#3}{#4}{#5}{#6}{#7}{#8}
}
\def\databaseone{
\mcq{245}{Let $A$ be a symmetric matrix of order $n$ and $B$ be a
% no space in skew- symmetric
skew-symmetric matrix of order $n$. Then which one of the following is a skew-symmetric matrix?}{$A^{2}$}{$B^{2}$}{$AB+BA$}{$AB-BA$}{c}{}{}
\mcq{248}{A square matrix is a diagonal matrix if and only if it is}{upper triangular}{lower triangular}{both upper triangular and lower triangular}{none of these}{c}{}{}
\mcq{249}{Let $A$ be a non-singular matrix of order $3$. Then the rank of matrix $A^{2018}$ is}{$1$}{$2$}{$3$}{$9$}{c}{Note that $A^{2018}$ is a non-singular matrix of order $3$. Hence rank $(A^{2018})=3$.}{}
\mcq{250}{If $A=\begin{pmatrix}0 & 1 & 0\\0 & 0 & 1\\1 & 0 & 0\end{pmatrix}$, then rank of the matrix $A+A^{2}+A^{3}$ is}{$1$}{$2$}{$3$}{none of these}{a}{Note that $A+A^{2}+A^{3}=\protect\begin{pmatrix}1 & 1 & 1\\1 & 1 & 1\\1 & 1 & 1\protect\end{pmatrix}$. Hence rank $(A+A^{2}+A^{3})=1$}{}
}
\begin{document}
\chapter{One}
\begin{enumerate}
\databaseone
\end{enumerate}
%\bigskip
% NO (this makes entire document Huge \Huge{Answer Key:}
\section*{Answer Key:}
%\bigskip
\begin{center}
\begin{multicols}{6}
\showallanswerkeys
\end{multicols}
\end{center}
%\bigskip
%\Huge
\section*{Hint/Explanation of Selected Problems:}
%\bigskip\bigskip
\showallanswers
\chapter{Two}
\begin{enumerate}
\databaseone
\end{enumerate}
%\bigskip
%\Huge
\section*{Answer Key:}
%\bigskip
\begin{center}
\begin{multicols}{6}
\showallanswerkeys
\end{multicols}
\end{center}
%\bigskip
%\Huge
\section*{Hint/Explanation of Selected Problems:}
%\bigskip\bigskip
\showallanswers
\end{document}