我正在尝试添加问题类型:使用 EXAM Class 使用下面提到的代码匹配配对:[仅供参考:我正在将 HTML 表转换为 Latex 表。我正在使用 pdflatex 从下面提到的 tex 文件中获取 pdf。]
\documentclass[addpoints,answers,10pt]{exam}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{nonfloat}
\usepackage{caption}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{ifpdf}
\usepackage[export]{adjustbox}
\newenvironment{Figure}
{\par\medskip\noindent\minipage{\linewidth}}
{\endminipage\medskip\par}
\marksnotpoints
\bracketedpoints
\pointsdroppedatright
\qformat{Q. \thequestion: \thequestiontitle\hfill\thepoints}
\renewcommand{\thesubsubpart}{\arabic{subsubpart}}
\renewcommand{\thechoice}{\arabic{choice}}
\runningheadrule
\pagestyle{headandfoot}
\runningheader{Competitive Examination}{}{}
\firstpagefooter{}{Page \thepage}{}
\runningfooter{}{Page \thepage}{}
\footrule
\renewcommand{\thepartno}{\Alph{partno}}
\begin{document}
\begin{center} {\centering \textbf{\Large{Dummy Value}}} \end{center}
\small{ABCD1234} \hspace*{\fill}
\small{TERMINAL EXAMINATION} \hspace*{\fill}
\small{Marks: 60}
\newline
\small{SSC-SET1} \hspace*{\fill}
\small{Science (Ch - 1,2,3)} \hspace*{\fill}
\small{2\textonehalf Hours}
\newline
\noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}}
\begin{center} {\centering \textbf{SECTION A}} \end{center}
\begin{questions}
\titledquestion{Match the Pairs}[10]
\begin{table}[ht] \begin{tabular}{l l l} \hline \hline
A &
B &
\\
\ 1) Why this text is dummy over here &
\ a) there is not dummy text &
\\
\ 2) THis is one word &
\ b) THis is not the correct word &
\\
\ 3) This is dummy value al dfadf adf adfasdf \ ddfakdfaasdf .\ &
\ c) values are here for all fasdf ad asdfasdkfad.\ &
\\
\ 4) asd fads adsfkaj dkladjsflkadsf asdfa skdlj, asdfasdasdfasdfa &
\ d) adjfklasd fasldfjasdlkfjasdlkfadsflkja sdflkjasd;lfkjasd;lfkja;sldkfjals;dk\ &
\\
\ 5) asdfasdfjas;dlfkjaslkdalkdsjf;alksdjfasdklfads &
\ e) adjfklasdjfa;lksdjf;alskdjf;alskdjf;alksdjf;laksdjf;alksdfj;alksdfja;lksdfja;lksdfja;lskdfj;alksdjfalksdfjasdklfjas;dlfja;sdlkfalkdjfa;lkdsjf;alksdfaldfja;lsdkfja;lsdkjf;alskdfj;aldkjf;alksdjfalksddddddfajsdlkfja;lsdkjf ;alsdjf ;asdjf; ajdf;l j;asdlfj ;alkdjsf;laksejriaeidkl ja;dlkfja;slkdfj a;ldskfja;sdikdfka dof asdf asdfk;lajsd;flkaj d;lkfajsd;lfk ja;dsfj ;alskdjf; lkadsjf;alksdjf; alsdfkja;lskdjf;alsdjf;alsdkjf;alskdjf\ &
\\
\hline \end{tabular} \label{table:nonlin} \end{table}
\end{questions}
\end{document}
生成的输出如下
我在这段代码中遇到两个问题:
- 配对表位于问题标题上方
- 如果有较长的单词或更多的文本,则会超出页面宽度
您能给我指点如何解决这些错误吗?
答案1
这里还有一些关于 Phil 和 Werner 的回答需要补充:首先,对于列表结构,您应该考虑使用enumerate
环境;其次,即使使用tabularx
LaTeX 仍然会遇到一些麻烦,处理您示例中出现的极长单词,在这种情况下,您可以使用\hyphenation{...}
手动设置连字符或使用包\seqsplit{...}
提供的seqsplit
。现在这里有一个演示:
\usepackage{seqsplit}
这里我跳过了序言,因为它太长了
\begin{questions}
\titledquestion{Match the Pairs}[10]
\noindent
\begin{tabularx}{\linewidth}{XX}
\hline
\hline
A
\begin{enumerate}
\renewcommand{\labelenumi}{\arabic{enumi})}
\item Why this text is dummy over here
\item THis is one word
\item This is dummy value al dfadf adf adfasdf \ ddfakdfaasdf .
\item asd fads adsfkaj dkladjsflkadsf asdfa skdlj, asdfasdasdfasdfa
\item asdfasdfjas;dlfkjaslkdalkdsjf;alksdjfasdklfads
\end{enumerate}
&
B
\begin{enumerate}
\renewcommand{\labelenumi}{\alph{enumi})}
\item there is not dummy text
\item THis is not the correct word
\item values are here for all fasdf ad asdfasdkfad.
\item adjfklasd fasldfjasdlkfjasdlkfadsflkja sdflkjasd;lfkjasd;lfkja;sldkfjals;dk
\item
\seqsplit{adjfklasdjfa;lksdjf;alskdjf;alskdjf;alksdjf;laksdjf;alksdfj;alksdfja;lksdfja;lksdfja;lskdfj;alksdjfalksdfjasdklfjas;dlfja;sdlkfalkdjfa;lkdsjf;alksdfaldfja;lsdkfja;lsdkjf;alskdfj;aldkjf;alksdjfalksddddddfajsdlkfja;lsdkjf ;alsdjf ;asdjf; ajdf;l j;asdlfj ;alkdjsf;laksejriaeidkl ja;dlkfja;slkdfj a;ldskfja;sdikdfka dof asdf asdfk;lajsd;flkaj d;lkfajsd;lfk ja;dsfj ;alskdjf; lkadsjf;alksdjf; alsdfkja;lskdjf;alsdjf;alsdkjf;alskdjf}
\end{enumerate}
\\
\hline
\end{tabularx}
及其结果:
更新
在考虑了您的新请求一段时间后,我想到了一种模拟环境的方法enumerate
。tabularx
首先,我们需要定义两个新的计数器:
\newcounter{counterA}
\setcounter{counterA}{0}
\newcounter{counterB}
\setcounter{counterB}{0}
然后我们需要两种新的列类型:
\newcolumntype{A}{
@{
\stepcounter{counterA}
\hspace{\itemindent}
\arabic{counterA})
\hspace{\labelsep}
\vspace{\itemsep}
}X}
\newcolumntype{B}{
@{
\stepcounter{counterB}
\hspace{\itemindent}
\alph{counterA})
\hspace{\labelsep}
\vspace{\itemsep}
}X}
现在让我们检查一下代码(再次强调,这只是关键部分):
\begin{questions}
\titledquestion{Match the Pairs}[10]
\begin{tabularx}{\linewidth}{AB}
\hline
\hline
\multicolumn{2}{l}{A\hspace{216.46775pt}B}\\[\topsep]
Why this text is dummy over here &
there is not dummy text\\
THis is one word &
THis is not the correct word \\
This is dummy value al dfadf adf adfasdf \ ddfakdfaasdf . &
values are here for all fasdf ad asdfasdkfad.\\
asd fads adsfkaj dkladjsflkadsf asdfa skdlj, asdfasdasdfasdfa &
adjfklasd fasldfjasdlkfjasdlkfadsflkja sdflkjasd;lfkjasd;lfkja;sldkfjals;dk\\
asdfasdfjas;dlfkjaslkdalkdsjf;alksdjfasdklfads &
\seqsplit{adjfklasdjfa;lksdjf;alskdjf;alskdjf;alksdjf;laksdjf;alksdfj;alksdfja;lksdfja;lksdfja;lskdfj;alksdjfalksdfjasdklfjas;dlfja;sdlkfalkdjfa;lkdsjf;alksdfaldfja;lsdkfja;lsdkjf;alskdfj;aldkjf;alksdjfalksddddddfajsdlkfja;lsdkjf ;alsdjf ;asdjf; ajdf;l j;asdlfj ;alkdjsf;laksejriaeidkl ja;dlkfja;slkdfj a;ldskfja;sdikdfka dof asdf asdfk;lajsd;flkaj d;lkfajsd;lfk ja;dsfj ;alskdjf; lkadsjf;alksdjf; alsdfkja;lskdjf;alsdjf;alsdkjf;alskdjf}\\
\hline
\end{tabularx}
\end{questions}
这将给我们:
如您所见,我们得到的结果与enumerate
之前实现的环境非常相似,而且这次我们还实现了良好的垂直对齐。但是,这种方法仍然存在一些缺陷,例如:
- 有一些神秘的压痕是由
seqsplit
我不太明白造成的。 - 表格的第一行
\topsep
来自list
环境。我尝试将其放入列定义中,\ifnum
但失败了 :P 216.46775pt
是手动计算的0.5\linewidth-\columnsep
,我不知道如何calc
在表内进行工作所以我没有使用它。
等等等等。
答案2
要解决表格出现在问题标题上方的问题,您不应将tabular
环境置于环境内table
。table
环境是一个浮动环境,这实际上并不是您想要的,因为您希望表格准确地出现在您放置它的位置,即您不希望它浮动到其他位置。