我想创建一个 T 型帐户,如下图所示:
我曾尝试使用表格环境来执行此操作,但效果不佳(例如,当我在帐户的一侧(即左侧)只有文字/数字时,另一侧(右侧)的所有空间都会被删除)。
也许一个可行的解决方案是使用minipage
里面有两列的环境?
任何建议都值得赞赏!
\documentclass{article}
\begin{document}
\begin{table}[]
\centering
%\caption{My caption}
\label{my-label}
\begin{tabular}{|l|l|}
\hline
\multicolumn{2}{|c|}{Statement of Income 2015} \\ \hline
Debit & Credit \\ \hline
Increase & Decrease \\ \hline
Normal Balance & \\ \hline
\end{tabular}
\end{table}
\end{document}
答案1
(编辑以考虑到 OP 希望能够覆盖 t-account 的默认宽度)
下面是一个答案,它定义了一个名为的宏\taccount
,它接受四个参数,其中第一个是可选的:
- 每个 t 列的宽度;此参数是可选的。如果未指定,则默认为(在下面的代码中
\tcolumnwidth
设置为)1.75cm
- 帐户标题(居中,启用自动换行)
- 左侧(“资产”)列的材料(右侧不规则、启用换行、允许使用连字符)
- 右侧(“责任”)栏的材料(也是右边不齐、启用换行、允许使用连字符)
\documentclass{article}
\usepackage{array,ragged2e}
\newlength\tcolumnwidth
\setlength\tcolumnwidth{1.75cm} % default width of t-column
\newlength\taccountwidth
%% The macro "\taccount" takes 4 arguments. The first
%% arg. is optional; its default value is \tcolumnwidth.
\newcommand\taccount[4][\tcolumnwidth]{%
\renewcommand\arraystretch{1.333} % default value: 1
\setlength\tabcolsep{3pt} % default value: 6pt
\setlength\taccountwidth{\dimexpr#1+#1+2\tabcolsep+1\arrayrulewidth\relax}
\begin{tabular}[t]{@{}l|l@{}}
\multicolumn{2}{>{\Centering}p{\taccountwidth}}{#2}\\
\hline
\begin{tabular}[t]{@{}>{\RaggedRight\hspace{0pt}}p{#1}}
#3 \end{tabular}
&
\begin{tabular}[t]{>{\RaggedRight\hspace{0pt}}p{#1}@{}}
#4 \end{tabular}
\end{tabular}}
\begin{document}
% First instance of \taccount uses the default width;
% the second instance uses a non-default width.
\taccount{A basic T-account}
{Asset 1\\Asset 2\\Asset 3\\Asset 4}
{Liability 1\\Liability 2\\ Equity}
\qquad
\taccount[2.75cm]{A slightly more complicated T-account}
{Basic Asset 1\\Complicated Asset 2\\Asset 3\\Asset 4}
{Liability 1\\Complicated Liability 2\\Preferred Stock\\Common Equity}
\end{document}
答案2
下面的定义引入了宏
\Taccount[column width]{headline}{table contents}
第一个参数是可选的,默认为1.5cm
。
\newcommand\Taccount[3][1.5cm]%
{{\renewcommand\arraystretch{1.3}%
\begin{tabular}[t]{@{}p{#1}|p{#1}@{}}
\multicolumn{2}{@{}c@{}}{#2}\\
\hline
#3
\end{tabular}%
}}
行距由 控制\arraystretch
,这里增加到1.3
。
\documentclass{article}
\newcommand\Taccount[3][1.5cm]%
{{\renewcommand\arraystretch{1.3}%
\begin{tabular}[t]{@{}p{#1}|p{#1}@{}}
\multicolumn{2}{@{}c@{}}{#2}\\
\hline
#3
\end{tabular}%
}}
\begin{document}
\Taccount{Assets}{Debits&Credits\\Increase&Decrease\\Normal Balance}\quad
\Taccount{Expenses}{Debits&Credits\\Increase&Decrease\\Normal Balance}\quad
\Taccount{Owner's Drawing}{Debits&Credits\\Increase&Decrease\\Normal Balance}
\bigskip
\Taccount{Liabilities}{Debits&Credits\\Decrease&Increase\\&Normal Balance}\quad
\Taccount{Revenues}{Debits&Credits\\Decrease&Increase\\&Normal Balance}\quad
\Taccount{Owner's Capital}{Debits&Credits\\Decrease&Increase\\&Normal Balance}
\end{document}