我想知道我是否可以在 LaTeX 中制作某种表格,以便在文本中很好地显示我的 C 数组?我在 KolourPaint 中做了类似的事情:
尝试对 LaTeX 表执行相同操作,但没有成功...这可能吗?
到目前为止我只得到了类似的东西(我知道,这并不令人印象深刻):
\documentclass[11pt]{article}
\begin{document}
\begin{table}[ht]
\begin{center}
\begin{tabular}{|c|c|}
\multicolumn{2}{c}{tab[0] tab[1]}\\ \hline
123 & 23 \\ \hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}
答案1
这远远不够。但它确实有效。我希望有人能开发出更自动化的版本(我会甚至与我的解决方案相比,我更喜欢 TikZ)。
编辑我太傻了,把第一行和最后一行都设为 ,\multicolumn
而其实在中间一行使用起来更方便。我保持不变,因为我不喜欢 (:P) 这种解决方案。
\documentclass{scrartcl}
\begin{document}
\begin{tabular}{|c|c|c|}
\multicolumn{1}{c}{a} & \multicolumn{1}{c}{b} & \multicolumn{1}{c}{c} \\ \hline
c & d & e \\ \hline
\multicolumn{1}{c}{e} & \multicolumn{1}{c}{f} & \multicolumn{1}{c}{g}
\end{tabular}
\end{document}
下面是一些可以玩的东西tap
,因为它将 Plain Tex 与 Latex 混合,所以可能会破坏一些东西,但是......我喜欢输出(我也用过它这里)。
\documentclass{scrartcl}
\input{tap}
\begin{document}
\begintable
\begintableformat
& \center
\endtableformat
\B": \texttt{tab[0]} " \texttt{tab[1]} " \texttt{tab[2]} " \texttt{tab[3]} " \texttt{tab[4]} " \texttt{tab[5]} " \texttt{tab[6]} " \texttt{tab[7]} \E"
\=
\B!: 1234 ! 56 ! 1212 ! 33 ! 1434 ! 80 ! 1312 ! 78 \E!
\=
\B": 65508 " 65510 " 65512 " 65514 " 65516 " 65518 " 65520 " 65522 \E"
\endtable
\end{document}
答案2
考虑使用一些更简单的东西,像这样:
\documentclass{article}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\keys_define:nn { brian / c-array } {
name .tl_set:N = \l_brian_c_array_name_tl,
name-fmt .tl_set:N = \l_brian_c_array_name_fmt_tl,
index-start .int_set:N = \l_brian_c_array_index_int,
addr-start .int_set:N = \l_brian_c_array_addr_int,
addr-step .int_set:N = \l_brian_c_array_addr_step_int,
addr-fmt .tl_set:N = \l_brian_c_array_addr_fmt_tl,
inner-fmt .tl_set:N = \l_brian_c_array_inner_fmt_tl,
top-skip .dim_set:N = \l_brian_c_array_top_skip_dim,
bottom-skip .dim_set:N = \l_brian_c_array_bottom_skip_dim,
inner-strut .tl_set:N = \l_brian_c_array_inner_strut_tl,
}
\cs_new:Nn \__brian_temp:n{
& \multicolumn{1}{c|}{
\l_brian_c_array_inner_fmt_tl
#1
}
}
\NewDocumentCommand \CArray { O{} m O{\rule[-2.25ex]{0pt}{6ex}}} {
\group_begin:
\keys_set:nn
{ brian / c-array }
{ name=arr,
name-fmt=\ttfamily\small,
index-start=0,
addr-start=2000,
addr-step=4,
top-skip = \medskipamount,
bottom-skip = 3ex,
inner-strut = \rule[-2.25ex]{0pt}{6ex},
inner-fmt = \rmfamily,
addr-fmt = \rmfamily,
#1 }
\seq_set_split:Nnn \l_tmpa_seq { , } { #2 }
\seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
\int_set:Nn \l_tmpa_int { \seq_count:N \l_tmpa_seq }
\begin{tabular}{*{\int_eval:n { \seq_count:N \l_tmpa_seq + 1 }}{c}}
\tl_use:N \l_brian_c_array_name_fmt_tl
\tl_use:N \l_brian_c_array_name_tl
[\int_use:N \l_brian_c_array_index_int]
\prg_replicate:nn {\int_use:N \l_tmpa_int}
{
&
\int_gincr:N \l_brian_c_array_index_int
\tl_use:N \l_brian_c_array_name_fmt_tl
\tl_use:N \l_brian_c_array_name_tl
[\int_use:N \l_brian_c_array_index_int]
}
\\[\l_brian_c_array_top_skip_dim]
\hline
\multicolumn{1}{|c|}{
\l_brian_c_array_inner_strut_tl
\l_brian_c_array_inner_fmt_tl
\tl_use:N \l_tmpa_tl
}
\seq_map_function:NN \l_tmpa_seq \__brian_temp:n
\\
\hline
\rule{0pt}{\l_brian_c_array_bottom_skip_dim}
\l_brian_c_array_addr_fmt_tl
\int_use:N \l_brian_c_array_addr_int
\prg_replicate:nn { \int_use:N \l_tmpa_int }
{
& \int_gadd:Nn \l_brian_c_array_addr_int
{
\int_use:N \l_brian_c_array_addr_step_int
}
\l_brian_c_array_addr_fmt_tl
\int_use:N \l_brian_c_array_addr_int
}
\end{tabular}
\group_end:
}
\ExplSyntaxOff
\begin{document}
\centering
\CArray[
addr-start=65508,
addr-step=4,
name=tab,
name-fmt=\ttfamily\small,
inner-fmt=\ttfamily,
]{1234, 56, 1212, 33, 1434, 80, 1312, 78}
\vspace{1in}
\CArray[inner-fmt=\ttfamily\large,name-fmt=\ttfamily]
{1,2,3}
\end{document}
如果您确实想要表格阴影,我可以对其进行编辑。(首先,我需要弄清楚如何做:)
)
非常感谢@hugovdberg和@egreg为了理清中间的混乱和\seq_map_…:
。:)