Sorry to call for help once again!
With your help I could write a similar macro working perfectly for
"normal", short tables.
However, when adapting the code to longtables I have troubles.
The code won't compile, but the log doesn't show any problem.
Can you please help me?
Any suggestion welcome!
\documentclass{article}
\usepackage[latin1]{inputenc}% LaTeX source encoding
\usepackage[T1]{fontenc}% Font encoding
\usepackage{caption,floatrow,booktabs,array,longtable,multirow,tabularx}%Tools
for tables
\usepackage{xkeyval,lipsum}
\begin{filecontents}{File.tex}
% Headers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% First page header
\toprule
\textbf{Column A}
&\textbf{Column B}
&\textbf{Column C}
\tabularnewline
\midrule
\endfirsthead
% Other page header
\caption[]{(continued)}\\
\toprule
\textbf{Col. A}
&\textbf{Col. B}
&\textbf{Col. C}
\tabularnewline
\midrule
\endhead
% Footers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Other page footer
\tabularnewline
\midrule
\ldots
\endfoot
% Last page footer
\tabularnewline
\bottomrule
\endlastfoot
% Content %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1& 10& 100\tabularnewline
2& 20& 200\tabularnewline
3& 30& 300\tabularnewline
4& 40& 400\tabularnewline
5& 50& 500\tabularnewline
6& 60& 600\tabularnewline
7& 70& 700\tabularnewline
8& 80& 800\tabularnewline
9& 90& 900\tabularnewline
10& 100& 1000\tabularnewline
11& 110& 1100\tabularnewline
12& 120& 1200\tabularnewline
13& 130& 1300\tabularnewline
14& 140& 1400\tabularnewline
15& 150& 1500\tabularnewline
16& 160& 1600\tabularnewline
17& 170& 1700\tabularnewline
18& 180& 1800\tabularnewline
19& 190& 1900\tabularnewline
20& 200& 2000\tabularnewline
21& 210& 2100\tabularnewline
22& 220& 2200\tabularnewline
23& 230& 2300\tabularnewline
24& 240& 2400\tabularnewline
25& 250& 2500\tabularnewline
26& 260& 2600\tabularnewline
27& 270& 2700\tabularnewline
28& 280& 2800\tabularnewline
29& 290& 2900\tabularnewline
30& 300& 3000\tabularnewline
31& 310& 3100\tabularnewline
32& 320& 3200\tabularnewline
33& 330& 3300\tabularnewline
34& 340& 3400\tabularnewline
35& 350& 3500\tabularnewline
36& 360& 3600\tabularnewline
37& 370& 3700\tabularnewline
38& 380& 3800\tabularnewline
39& 390& 3900\tabularnewline
40& 400& 4000\tabularnewline
41& 410& 4100\tabularnewline
42& 420& 4200\tabularnewline
43& 430& 4300\tabularnewline
44& 440& 4400\tabularnewline
45& 450& 4500\tabularnewline
46& 460& 4600\tabularnewline
47& 470& 4700\tabularnewline
48& 480& 4800\tabularnewline
49& 490& 4900\tabularnewline
50& 500& 5000\tabularnewline
\end{filecontents}
\begin{document}
\makeatletter%
\define@cmdkeys[MG]{table}{%
,caption%
,defcolumns%
,file%
,label%
,shortcaption%
}%
\presetkeys[MG]{table}{%
,caption=\null%
,defcolumns={}%
,file={}%
,label=NoLabel%
,shortcaption=\null%
}{}%
\newcommand*{\InsLongTab}[2][float]{%
\def\longtable@code{%
\setkeys[MG]{table}{#2}%
% \begin{longtable}{\cmdMG@table@defcolumns}% Expansion problem
% Solution 1
\begingroup\edef\process@me{%
\endgroup\noexpand\begin{longtable}{\cmdMG@table@defcolumns}%
}\process@me%
% Solution 2
% \def\process@me{\begin{longtable}}%
% \expandafter\process@me\expandafter{\cmdMG@table@defcolumns}%
\ifthenelse{\equal{\cmdMG@table@shortcaption}{\null}}{%
\caption{\cmdMG@table@caption}% Caption without short version
}{%
\caption[\cmdMG@table@shortcaption]{\cmdMG@table@caption}%
Caption with short version
}%
\label{\cmdMG@table@label}\\%
\@@input \cmdMG@table@file.tex%
\end{longtable}%
}%
\ifthenelse{\equal{#1}{float}}{%
\afterpage{\clearpage%
\longtable@code%
}%
}{%
\floatplacement{table}{H}%
\longtable@code%
\floatplacement{table}{tbp}%
}%
}%
\makeatother%
\InsFig[float]{
defcolumns={ccc}
,label=tab-Label2
,file=File.tex
,shortcaption=ShortCaption2
,caption=LongCaption2%\\\lipsum[2]
}
\end{document}
The following modified example seems to work fine.
\documentclass{article}
\usepackage[latin1]{inputenc}% LaTeX source encoding
\usepackage[T1]{fontenc}% Font encoding
\usepackage{caption,floatrow,booktabs,array,longtable,multirow,tabularx}%Tools
for tables
\usepackage{xkeyval,lipsum,ifthen,afterpage}
\makeatletter
\define@cmdkeys[MG]{table}{%
,caption
,defcolumns
,file
,label
,shortcaption
}%
\presetkeys[MG]{table}{%
,caption=\null
,defcolumns={}
,file={}
,label=NoLabel
,shortcaption=\cmdMG@table@caption
}{}%
\def\longtable@code#1{%
\setkeys[MG]{table}{#1}%
\begingroup\edef\process@me{%
\endgroup\noexpand\begin{longtable}{\cmdMG@table@defcolumns}}%
\process@me
\caption[\cmdMG@table@shortcaption]{\cmdMG@table@caption}
\label{\cmdMG@table@label} \\
\@@input \cmdMG@table@file.tex%
\end{longtable}%
}%
\newcommand*{\InsLongTab}[2][float]{%
\ifthenelse{\equal{#1}{float}}{%
\afterpage{\clearpage
\longtable@code{#2}%
}%
}{%
\floatplacement{table}{H}%
\longtable@code{#2}%
\floatplacement{table}{tbp}%
}%
}%
\makeatother
\begin{document}
\InsLongTab[float]{
defcolumns={ccc}
,label=tab-Label2
,file=File
,shortcaption=ShortCaption2
,caption=LongCaption2%\\\lipsum[2]
}
\end{document}
--
Joseph Wright
The example works, but for some reason I cannot identify, when I
integrate it into my framework, I once again cannot get it to compile:
is it important to have \def and \newcommand* before \begin{document}?
Because that's the only difference I can see... appart from conflict
with another package maybe?
Best regards,
Mathieu
Just for tidiness, really. Having stuff in the preamble cuts down the
opportunity for stray spaces to appear.
Follow the usual advice on an issue. Either add things one at a time to
the example, or start with a copy of the real problem and chop out bits
until you find which one(s) cause the issue.
--
Joseph Wright
OK, thank you.
I got it to work, it looks like a \makeatother was incorrectly written
as \makeatletter...
Thank you!
Sorry, me again!
This time everything work for easy column settings... but as soon as I
go from
\InsLongTab[here]{
defcolumns=ccc
,label=tab-Label2
,file=TemplateLongTab
,shortcaption=ShortCaption2
,caption=LongCaption2
}%
to
\InsLongTab[here]{
defcolumns=*{3}{>{\centering}p{.2\textwidth}}
,label=tab-Label2
,file=TemplateLongTab
,shortcaption=ShortCaption2
,caption=LongCaption2
}%
I have troubles! My tests tell me the trouble come from the >{} part...
but I have unfortunately no idea how to solve this!
Can you help me please?
Mathieu
>
> Sorry, me again!
>
> This time everything work for easy column settings... but as soon as I
> go from
>
> \InsLongTab[here]{
> defcolumns=ccc
> ,label=tab-Label2
> ,file=TemplateLongTab
> ,shortcaption=ShortCaption2
> ,caption=LongCaption2
> }%
>
> to
>
> \InsLongTab[here]{
> defcolumns=*{3}{>{\centering}p{.2\textwidth}}
> ,label=tab-Label2
> ,file=TemplateLongTab
> ,shortcaption=ShortCaption2
> ,caption=LongCaption2
> }%
>
>
> I have troubles! My tests tell me the trouble come from the >{} part...
> but I have unfortunately no idea how to solve this!
>
Use this to define the key defcolumns:
\define@key[MG]{table}{defcolumns}{\newcolumntype{M}{#1}}
and then use \begin{longtable}{M} in the code.
--
Ulrike Fischer
Vielen dank!
> Ulrike Fischer a écrit :
> > Am Thu, 24 Jul 2008 16:39:59 +0200 schrieb Mathieu G:
> >
> >> defcolumns=*{3}{>{\centering}p{.2\textwidth}}
> >> I have troubles! My tests tell me the trouble come from the >{} part...
> >> but I have unfortunately no idea how to solve this!
> >
> > Use this to define the key defcolumns:
> >
> > \define@key[MG]{table}{defcolumns}{\newcolumntype{M}{#1}}
> >
> > and then use \begin{longtable}{M} in the code.
> >
> >
> Wow! Great! No more expansion problem, no nothing! :-)
> Really clean!
Of course the best solution.
Just for the record, it can also be done via the
expansion route. However \cmdMG@table@defcolumns
should be expanded once exactly. This can be done
by the help of a token register (\toks@ is a general purpose/
scratch/temporary token register):
\begingroup
\toks@\expandafter{\cmdMG@table@defcolumns}%
\edef\process@me{%
\endgroup
\noexpand\begin{longtable}{\the\toks@}%
}%
\process@me
Or e-TeX's \unexpanded can be used:
\begingroup
\edef\process@me{%
\endgroup
\noexpand\begin{longtable}{%
\unexpanded\expandafter{\cmdMG@table@defcolumns}%
}%
}%
\process@me
Viele Grüße
Heiko <ober...@uni-freiburg.de>
Where did you get to know all that? In the TeXbook mainly?
I have to spend more time with it!
Viele Grüsse!
Mathieu
> Where did you get to know all that? In the TeXbook mainly?
That was the start.
Yours sincerely
Heiko <ober...@uni-freiburg.de>