Re: tabular環境内の環境作成

名前: .
日時: 2009-01-30 21:16:39
IPアドレス: 59.134.169.*

>>52632 「表」にこだわると,次の例のように面倒なことになると思いますが. \documentclass{jarticle} \usepackage{longtable,calc,array} \makeatletter \newcounter{EntryNo} \newdimen\EntryWidth \setlength{\EntryWidth}{45pt} \def\Entry{% \setbox0\hbox\bgroup \stepcounter{EntryNo}% \let\@ItemA\@empty \let\@ItemC\@empty \let\@ItemD\@empty \let\@ItemE\@empty \let\@ItemB\@empty \let\@ItemBopt\@empty} \def\endEntry{% \edef\@tempa{\toks0{% & \noexpand\multicolumn{4}{l|}{Entry \arabic{EntryNo}}% \noexpand\\*\noexpand\hline}}% \@tempa \toks2\expandafter{\@ItemA}% \edef\@tempa{\the\toks0 & Item A & \noexpand\multicolumn{3}{l|}{\the\toks2}% \noexpand\\*\noexpand\hline}% \toks0\expandafter{\@tempa}% \toks2\expandafter{\@ItemB}% \toks4\expandafter{\@ItemBopt}% \edef\@tempa{\the\toks0 & Item B & \noexpand\multicolumn{2}% {p{2\EntryWidth + 2\tabcolsep + \arrayrulewidth}|}% {\the\toks2}% & \the\toks4 \noexpand\\*\noexpand\hline}% \toks0\expandafter{\@tempa}% \toks2\expandafter{\@ItemC}% \toks4\expandafter{\@ItemD}% \edef\@tempa{\the\toks0 & Item C & \the\toks2 & Item D & \the\toks4 \noexpand\\*\noexpand\hline}% \toks0\expandafter{\@tempa}% \toks2\expandafter{\@ItemE}% \edef\@tempa{\the\toks0 & Item E & \noexpand\multicolumn{3}% {p{3\EntryWidth + 4\tabcolsep + 2\arrayrulewidth}|}% {\the\toks2}% \noexpand\\*\noexpand\hline}% \global\let\g@Entry\@tempa \egroup \aftergroup\g@Entry} \def\ItemA{\@item@in@entry\@ItemA} \def\ItemC{\@item@in@entry\@ItemC} \def\ItemD{\@item@in@entry\@ItemD} \def\ItemE{\@item@in@entry\@ItemE} \long\def\@item@in@entry#1#2{\def#1{#2}} \def\ItemB{\@testopt\ItemB@{}} \long\def\ItemB@[#1]#2{\def\@ItemBopt{#1}\def\@ItemB{#2}} \makeatother \begin{document} \begin{longtable}{@{}c@{}|*{4}{p{\EntryWidth}|}} \hline \endhead \begin{Entry} \end{Entry} \begin{Entry} \ItemA{aaa} \ItemB{bbb} \ItemC{ccc} \ItemD{ddd} \ItemE{This is a meaningless sample.} \end{Entry} \begin{Entry} \ItemA{AAA} \ItemB[xxx]{BBB} \ItemC{CCC} \ItemD{DDD} \ItemE{This is a meaningless sample. This is a meaningless sample. This is a meaningless sample. This is a meaningless sample. This is a meaningless sample.} \end{Entry} \end{longtable} \end{document} 次の例のようにボックスと罫線を直接組み立てるほうが(手間はかかっても) 難しいこと(あるいは変な細工)を使わずに済むでしょう. \documentclass{jarticle} \makeatletter \newcounter{EntryNo} \newdimen\EntryWidth \setlength{\EntryWidth}{45pt} \setlength{\fboxsep}{6pt} \def\Entry{% \par \ifnum\c@EntryNo>\z@ \nointerlineskip\vskip-\fboxrule \fi \noindent \vbox\bgroup \stepcounter{EntryNo}% \let\@ItemA\@empty \let\@ItemC\@empty \let\@ItemD\@empty \let\@ItemE\@empty \let\@ItemB\@empty \let\@ItemBopt\@empty} \def\endEntry{% \@tempdima=2\fboxsep \advance\@tempdima\EntryWidth \@tempdimb\@tempdima \advance\@tempdima\fboxrule \hrule height\fboxrule \hbox{\vrule width\fboxrule \kern\fboxsep \dimen@=3\@tempdima \advance\dimen@\EntryWidth \vbox{\vskip\fboxsep \hbox to\dimen@{Entry \arabic{EntryNo}\hfill}% \vskip\fboxsep}% \kern\fboxsep \vrule width\fboxrule}% \hrule height\fboxrule \hbox{% \rlap{% \vbox{\vskip\fboxsep \hbox{% \kern\fboxrule \kern\fboxsep \hbox to\EntryWidth{Item A\hfill}% \kern2\fboxsep \kern\fboxrule \dimen@=2\@tempdima \advance\dimen@\EntryWidth \vtop{\hsize\dimen@ \@parboxrestore \@ItemA}}% \vskip\fboxsep}}% \vrule width\fboxrule \kern\@tempdimb \vrule width\fboxrule \kern2\@tempdima \kern\@tempdimb \vrule width\fboxrule}% \hrule height\fboxrule \hbox{% \rlap{% \vbox{\vskip\fboxsep \hbox{% \kern\fboxrule \kern\fboxsep \hbox to\EntryWidth{Item B\hfill}% \kern2\fboxsep \kern\fboxrule \dimen@\@tempdima \advance\dimen@\EntryWidth \vtop{\hsize\dimen@ \@parboxrestore \@ItemB}% \kern2\fboxsep \kern\fboxrule \hbox to\EntryWidth{\@ItemBopt\hfill}}% \vskip\fboxsep}}% \vrule width\fboxrule \kern\@tempdimb \vrule width\fboxrule \kern\@tempdima \kern\@tempdimb \vrule width\fboxrule \kern\@tempdimb \vrule width\fboxrule}% \hrule height\fboxrule \hbox{% \rlap{% \vbox{\vskip\fboxsep \hbox{% \kern\fboxrule \kern\fboxsep \hbox to\EntryWidth{Item C\hfill}% \kern2\fboxsep \kern\fboxrule \hbox to\EntryWidth{\@ItemC\hfill}% \kern2\fboxsep \kern\fboxrule \hbox to\EntryWidth{Item D\hfill}% \kern2\fboxsep \kern\fboxrule \hbox to\EntryWidth{\@ItemD\hfill}}% \vskip\fboxsep}}% \vrule width\fboxrule \kern\@tempdimb \vrule width\fboxrule \kern\@tempdimb \vrule width\fboxrule \kern\@tempdimb \vrule width\fboxrule \kern\@tempdimb \vrule width\fboxrule}% \hrule height\fboxrule \hbox{% \rlap{% \vbox{\vskip\fboxsep \hbox{% \kern\fboxrule \kern\fboxsep \hbox to\EntryWidth{Item E\hfill}% \kern2\fboxsep \kern\fboxrule \dimen@=2\@tempdima \advance\dimen@\EntryWidth \vtop{\hsize\dimen@ \@parboxrestore \@ItemE}}% \vskip\fboxsep}}% \vrule width\fboxrule \kern\@tempdimb \vrule width\fboxrule \kern2\@tempdima \kern\@tempdimb \vrule width\fboxrule}% \hrule height\fboxrule \egroup} \def\ItemA{\@item@in@entry\@ItemA} \def\ItemC{\@item@in@entry\@ItemC} \def\ItemD{\@item@in@entry\@ItemD} \def\ItemE{\@item@in@entry\@ItemE} \long\def\@item@in@entry#1#2{\def#1{#2}} \def\ItemB{\@testopt\ItemB@{}} \long\def\ItemB@[#1]#2{\def\@ItemBopt{#1}\def\@ItemB{#2}} \makeatother \raggedbottom \begin{document} \begin{center} \begin{Entry} \end{Entry} \begin{Entry} \ItemA{aaa} \ItemB{bbb} \ItemC{ccc} \ItemD{ddd} \ItemE{This is a meaningless sample.} \end{Entry} \begin{Entry} \ItemA{AAA} \ItemB[xxx]{BBB} \ItemC{CCC} \ItemD{DDD} \ItemE{This is a meaningless sample. This is a meaningless sample. This is a meaningless sample. This is a meaningless sample. This is a meaningless sample.} \end{Entry} \end{center} \end{document}

この書き込みへの返事:

お名前
題名 
メッセージ(タグは <a href="...">...</a> だけ使えます。適宜改行を入れてください)