带标签的表格命令

带标签的表格命令

如何为顶部带有标签的 2 个表格创建一个命令,并为下面的选项创建一个命令?我所说的例子是:

在此处输入图片描述

答案1

以下是实现您想要的简单方法。如果您愿意,我会进一步说明:

在此处输入图片描述

\documentclass{article}
\usepackage[margin=1in]{geometry}  % http://ctan.org/pkg/geometry
\usepackage{lipsum,tabularx,array} % http://ctan.org/pkg/{lipsum,tabularx}
\usepackage{multicol,enumitem}     % enables multicolumns and custom enumeration

\setlength{\parindent}{0pt}
\begin{document}
%
Write the following in its proper places.\\[2ex]
% This defines the new column type to have the words Good and Bad centered to fit what the OP wants. 
% Unfortunately, I couldn't figure out how to have it in a single table. Probably a using \multicolumn might work.
\newcolumntype{C}{>{\centering\arraybackslash}X} 
\begin{tabularx}{\linewidth}{CC}
Good & Bad
\end{tabularx}
%
\begin{tabularx}{\linewidth}{|X|X|}
\hline
  & \\[5cm] % Increase or decrease the table height
\hline
\end{tabularx}
% Declare the options here
\begin{multicols}{5}
\begin{itemize}[label=$-$]
\item Smoking
\item Drinking liquor
\item Exercise
\item Studying
\item Fighting
\item Vegetables
\item Crying
\item Sitting
\item Lying
\item Honest
\item Brave
\end{itemize}
\end{multicols}
\end{document}

你能从这里弄清楚吗?也就是说,如何创建命令?


将以上内容作为参考,供您比较命令的定义和选项的应用以实现结果:

\documentclass{article}
\usepackage[margin=1in]{geometry}    % http://ctan.org/pkg/geometry
\usepackage{lipsum,tabularx,array}   % http://ctan.org/pkg/{lipsum,tabularx}
\usepackage{multicol,enumitem,tikz}  % TiKZ offers the \foreach command used below.
\setlength{\parindent}{0pt}

\newcolumntype{C}{>{\centering\arraybackslash}X}%

% Defining the table with 3 options: 2 for table headers and one for the desired height
% for the table.
\newcommand{\tableclassification}[3]{%
\begin{tabularx}{\linewidth}{CC}
#1 & #2
\end{tabularx}
\begin{tabularx}{\linewidth}{|X|X|}
\hline
  & \\[#3] % Increase or decrease the table height
\hline
\end{tabularx}
}

% Offers a simple command to get the options for the table. The first option controls the
% controls the number of columns to be used and the last controls the data or options.
\newcommand{\tableoptions}[2]{%
\begin{multicols}{#1}
\begin{itemize}[label=$-$]
\foreach \tabopt in {#2}
{%
\item \tabopt%
}
\end{itemize}
\end{multicols}
}

\begin{document}
\tableclassification{Good}{Bad}{5cm}
\tableoptions{5}{Smoking, Drinking Liquor, Exercise, Studying, Fighting, Vegetables, Crying, Sitting, Lying, Honest, Brave}
\end{document}

相关内容