![使用 tikz、tcolorbox 或 tabular 的 mcq 长表](https://linux22.com/image/343761/%E4%BD%BF%E7%94%A8%20tikz%E3%80%81tcolorbox%20%E6%88%96%20tabular%20%E7%9A%84%20mcq%20%E9%95%BF%E8%A1%A8.png)
我需要用不同的方式创建类似的表格:
- 第一种方式使用
tabular
,tabularx
- 第二种方式使用
Tikz
- 第三种方式使用
tcolorbox
- 我该如何实现这一点?非常感谢任何帮助!
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsthm,amsmath,amssymb,amsmath,amsfonts,mathtools}
\usepackage{multirow,tabularx}
\begin{document}
\begin{center}
\sffamily
\begin{tabularx}{\textwidth}{|>{\bfseries\centering\hsize=0.12\hsize}X|
>{\centering\hsize=0.30\hsize}X|
>{\hsize=0.50\hsize}X|
c|
>{\hsize=0.10\hsize}X|}
\hline
Number of question
& \hfil\textbf{Question}
& \multicolumn{2}{>{\centering\hsize=0.5\hsize}X|}{%
\textbf{Choose the correct answer from the four alternatives}}
& \hfil\textbf{Marks} \\ \hline
\multirow{8}{*}{\Large 01}
& If $A=\{x\in\mathbb{C}\ :\ x^{2}=1 \}$ & \centering $\{-1,1 \}$
& \fbox{} & \\ \cline{3-5}
&and $B=\{x\in\mathbb{C}: x^{4}=1, \}$ & \centering $\{-1,1,i,-i \}$
& \fbox{} & \\ \cline{3-5}
& then $A\Delta B$ & \centering $\{-i,i \}$
& \fbox{} & \\ \cline{3-5}
& & \centering None of these
& \fbox{} & \\ \hline
\multirow{8}{*}{\Large 02}
& Let $\mathcal{R}$ be a relation in the set $N$ & reflexive and symmetric only
& \fbox{} & \\ \cline{3-5}
& of natural numbers defined bu the relattion $n\mathcal{R}m \iff n $ & symmetric and transitive only
& \fbox{} & \\ \cline{3-5}
& is a factor of $ m $ & reflexive and transitive only
& \fbox{} & \\ \cline{3-5}
& The relation $\mathcal{R} is $ & \centering and equivalence relation
& \fbox{} & \\ \hline
\end{tabularx}
\end{center}
\end{document}
但我需要有人修复它让它看起来好看
- 中心细胞
- 每个问题一个大单元格,附有四个语句行,作为我的第二张照片
答案1
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx}
\begin{document}
\begin{center}
\sffamily
\begin{tabularx}{\textwidth}{|>{\bfseries\centering\hsize=0.12\hsize}X|
>{\hsize=0.20\hsize}X|
>{\hsize=0.45\hsize}X|
c|
>{\hsize=0.20\hsize}X|}
\hline
Number of question
& \hfil\textbf{Question}
& \multicolumn{2}{>{\centering\hsize=0.5\hsize}X|}{%
\textbf{Choose the correct answer from the four alternatives}}
& \hfil\textbf{Marks} \\ \hline
\multirow{8}{*}{\Large 01}
& statement A & A statement 1 bla bla bla bla bla bla bla bla bla bla bla bla
& \fbox{} & \\ \cline{2-5}
& statement B & A statement 2 bla bla bla bla bla bla bla bla bla bla bla bla
& \fbox{} & \\ \cline{2-5}
& statement C & A statement 3 bla bla bla bla bla bla bla bla bla bla bla bla
& \fbox{} & \\ \cline{2-5}
& statement D & A statement 4 bla bla bla bla bla bla bla bla bla bla bla bla
& \fbox{} & \\ \hline
\end{tabularx}
\end{center}
\end{document}
您的代码(第一个版本)存在许多严重的问题:
- 和失踪
\begin{document}
\end{center}
- 声明和使用的列数不一致
\hline
禁止在牢房内使用- 即使是空单元格也必须以 & 符号开头
附录: 我猜你现在想获得这样的东西:
代码中标出了新的或更改的行。这应该有助于您理解下面的代码。注意:如果您安装了最近的multirow
包(旧包没有定义=
选项),这将有效!
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsthm,amssymb,amsfonts,mathtools}
\usepackage{multirow,tabularx}
\begin{document}
\begin{center}
\sffamily
\renewcommand\arraystretch{1.5}% <-- added
\setlength\tabcolsep{4pt}% <-- added
\begin{tabularx}{\textwidth}{|>{\bfseries\centering\hsize=0.12\hsize}X|
>{\centering\hsize=0.47\hsize}X|% <-- changed
>{\centering\hsize=0.33\hsize}X|% <-- changed
>{\centering\hsize=0.02\hsize}X|% <-- changed
>{\centering\arraybackslash\hsize=0.07\hsize}X|}% <-- changed
\hline
Number of question
& \textbf{Question}
& \multicolumn{2}{>{\centering\hsize=0.35\hsize}X|}{%
\textbf{Choose the correct answer from the four alternatives}}
& \textbf{Marks} \\ \hline
\multirow{4}{*}{\Large 01}% <-- changed number of lines
& \multirow{4}{=}{% <-- added
If $A=\{x\in\mathbb{C}\ :\ x^{2}=1 \}$
and $B=\{x\in\mathbb{C}: x^{4}=1, \}$
then $A\Delta B$}
& $\{-1,1 \}$ & $\square$ & \\ \cline{3-5}
& & $\{-1,1,i,-i \}$ & $\square$ & \\ \cline{3-5}
& & $\{-i,i \}$ & $\square$ & \\ \cline{3-5}
& & None of these & $\square$ & \\ \hline
\multirow{3}{*}{\Large 02}% <-- changed number of lines
& \multirow{3}{=}{% <-- added
Let $\mathcal{R}$ be a relation in the set $N$
is a factor of $m$ reflexive and transitive only
of natural numbers defined but the relation $n\mathcal{R}m \iff n $, then
the relation $\mathcal{R}$ is:}
& reflexive and symmetric only & $\square$ & \\ \cline{3-5}
& & symmetric and transitive only & $\square$ & \\ \cline{3-5}
& & and equivalence relation & $\square$ & \\ \hline
\end{tabularx}
\end{center}
\end{document}
我恳请您现在停止对同一问题提出新问题,如果有任何进一步的改进/希望等,请提出新问题。最近的请求实际上是新问题...
答案2
通过您的评论和问题的版本,您实际上提出了新的问题......请允许我写新的答案:-)
根据集成示例tabularx
和tcolorbox
包装手册第 66 页彩色盒子,版本 3.59(2016/10/21 起):
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{array,multirow,tabularx}
\usepackage[table,svgnames]{xcolor}
\usepackage[many]{tcolorbox}
\begin{document}
\tcbset{enhanced,
fonttitle=\bfseries\large\sffamily,
fontupper=\normalsize\sffamily,
colback=yellow!10!white, colframe=red!50!black,
colbacktitle=Salmon!30!white,
coltitle=black, center title}
\begin{tcolorbox}[tabularx={|>{\bfseries\centering\hsize=0.12\hsize}X|
>{\hsize=0.20\hsize}X|
>{\hsize=0.45\hsize}X|
c|
>{\hsize=0.20\hsize}X|},
title=My table]
Number of question
& \hfil\textbf{Question}
& \multicolumn{2}{>{\centering\hsize=0.5\hsize}X|}{%
\textbf{Choose the correct answer from the four alternatives}}
& \hfil\textbf{Marks} \\ \hline
\multirow{8}{*}{\Large 01}
& statement A & A statement 1 bla bla bla bla bla bla bla bla bla bla bla bla
& \fbox{} & \\ \cline{2-5}
& statement B & A statement 2 bla bla bla bla bla bla bla bla bla bla bla bla
& \fbox{} & \\ \cline{2-5}
& statement C & A statement 3 bla bla bla bla bla bla bla bla bla bla bla bla
& \fbox{} & \\ \cline{2-5}
& statement D & A statement 4 bla bla bla bla bla bla bla bla bla bla bla bla
& \fbox{} & \\ \hline
\end{tcolorbox}
\end{document}