4

I have a great example of using \ifodd condition if \makeatletter environment showed by @Symbol 1.

\begin{document}
\makeatletter
\newbox\LT@oddhead
\newbox\LT@evenhead
\def\endoddhead{\LT@end@hd@ft\LT@oddhead}
\def\endevenhead{\LT@end@hd@ft\LT@evenhead}
\def\LT@head{\ifodd\c@page\LT@oddhead\else\LT@evenhead}
\makeatother
\begin{landscape}\small\begin{longtabu}to\linewidth{lll XX XXXXX}
    \caption*{ Long caption of a long table}\\\toprule1&2&3&4&5&6&7&8\\\midrule\endfirsthead
    \caption*{ (Cont) Long caption of a long table }\\\toprule1&2&3&4&5&6&7&8\\\midrule\endoddhead
    \toprule1&2&3&4&5&6&7&8\\\midrule\endevenhead

I want to add one more statement to check if pagenumber is equal to some constant. For example:

\def\LT@head{\ifeq\c@page={some constant}\{some stuff}\else\LT@head}

But I can't find analoge for \ifodd command in \makeatletter environment. Any ideas?

EDIT: add minimal working example EDIT2: reduced MWE and added @-sign before someconstant. If I will uncomment line with \ifnum compiler won't make a pdf. The warning message is ! Missing number, treated as zero.. I'm still confused.

\documentclass[a4paper, 10pt, oneside,hidelinks]{book} 
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage{booktabs}
\usepackage{lscape}
\usepackage{tabu}
\usepackage{longtable}



\begin{document}
\makeatletter
\newbox\LT@oddhead
\newbox\LT@evenhead
\newbox\LT@endhead
\newcommand{\@someconstant}{2}
\newcommand{\Endd}{End}
\def\endoddhead{\LT@end@hd@ft\LT@oddhead}
\def\endevenhead{\LT@end@hd@ft\LT@evenhead}
\def\endendhead{\LT@end@hd@ft\LT@endhead}
\def\LT@head{\ifodd\c@page\LT@oddhead\else\LT@evenhead}
%\def\LT@head{\ifnum\c@page=\@someconstant\relax\Endd\else\LT@head\fi}
\makeatother



\begin{landscape}
  \small
\begin{longtabu} to \linewidth{ lll XX  XXXXX}

\caption*{ Long caption of a long table}\\\toprule1&2&3&4&5&6&7&8\\\midrule\endfirsthead
    \caption*{ (Cont) Long caption of a long table }\\\toprule1&2&3&4&5&6&7&8\\\midrule\endoddhead
    \toprule1&2&3&4&5&6&7&8\\\midrule\endevenhead
    End\\\endendhead


  \bottomrule
  \endfoot

  \bottomrule
  \endlastfoot




1-й

 & Длина, мм & Самцы & —
 & 85,1--104,0 93,7 (6) & 100,6 (1) & —
 & —
 & —
 & —
 \\ &  & Самки & —
 & 92,1--105,8 97,6 (4) & 137,6 (1) & —
 & —
 & —
 & —
 \\ 
 &  & juv & 43,6–82,0 53,3 (20) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
 & Масса, г & Самцы & —
 & 2,3--4,2 \linebreak2,8 (6) & 3,2 (1) & —
 & —
 & —
 & —
 \\ 
 &  & Самки & —
 & 2,2--3,6\linebreak 2,7 (4) & 7,9 (1) & —
 & —
 & —
 & —
 \\ 
 &  & juv & 0,2--1,8\linebreak 0,4 (20) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
\\

2-й & Длина, мм & Самцы & —
 & 72,0--114,0
93,6 (16) & 104,3--132,3
113,4 (4) & 121,5--178,2
139,3 (9) & 
158,9 (1) & 193,7--212,7
175,6 (3) & —
 \\ 
 &  & Самки & —
 & 77,5--110,4
95,2 (7) & 110,4--131,3
117,6 (4) & 167,8 (1) & —
 & 182,9 (1) & —
 \\ 
 &  & juv & 45,1--86,9
51,9 (40) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
 & Масса, г & Самцы & —
 & 1,1--5,1 \linebreak 2,7 (16) & 3,7--5,5 \linebreak 4,3  (4) &
 5,1--15,0\linebreak  9,2 (9) 
 & 17,0 (1) & 21,0--30,0 26,3 (3) & —
 \\ 
 &  & Самки & —
 & 1,5--4,7
\linebreak2,8 (7) & 4,0--6,1
\linebreak5,1 (4) & 15,0 (1) & —
 & 34,0 (1) & —
 \\ 
 &  & juv & 0,2--1,3
\linebreak0,4 (40) & —
 & —
 & —
 & —
 & —
 & —
 \\ 

\\

3-й & Длина, мм & Самцы & —
 & 85,8--114,6
100,4 (7) & 113,7--131,2
118,3 (5) & 124,0--172,7
148,3 (2) & 144,6  (1)
 & —
 & 181,7--184,0
182,8 (2) \\ 
 &  & Самки & —
 & 84,7--115,7
98,0 (9) & 109,1--156,4
133,3 (3) & 106,9--167,1
140,0 (3) & 159,3 (1) & 222,6 (1) & 170,2 (1) \\ 
 &  & juv & 42,3--90,4
61,0 (26) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
 & Масса, г & Самцы & —
 & 2,1--5,2
\linebreak3,7 (7) & 4,5--10,0
\linebreak5,8 (5) & 7,6--19,0
\linebreak13,3 (2) & 11,0 (1) & —
 & 23,5--24,9
24,2 (2) \\ 
 &  & Самки & —
 & 2,0--5,9
\linebreak3,5 (9) & 4,9--14,0
\linebreak9,7 (3) & 4,5--21,0
\linebreak12,5 (3) & 15,0 (1) & 39,0 (1) & 18,0 (1) \\ 
 &  & juv & 0,3--2,6
\linebreak0,9 (26) & —
 & —
 & —
 & —
 & —
 & —
 \\ 

\\

4-й & Длина, мм & Самцы & —
 & 77,6--112,0
92,7 (14) & 115,2--140,2
127,7 (2) & 135,2 (1) & 146,1--181,1
159,9 (3) & 157,9 (1) & 175,4--244,7
210,0 (2) \\ 
 &  & Самки & —
 & 88,0--113,7
99,1 (4) & 105,0--157,1
135,4 (6) & 123,0--174,3
141,3 (6) & 134,2--182,3
160,1 (3) & 181,6--187,0
183,4 (3) & —
 \\ 
 &  & juv & 43,9--81,0
52,0 (19) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
 & Масса, г & Самцы & —
 & 1,2--5,0
\linebreak2,7 (14) & 5,0--12,0
\linebreak8,5 (2) & 10,9 (1) & 12,0--23,0
\linebreak16,6 (3) & 13,4 (1) & 17,0 (1) \\ 
 &  & Самки & —
 & 2,0--6,0
\linebreak3,2 (4) & 4,3--17,0
\linebreak9,3 (6) & 7,0--26,0
\linebreak13,0 (6) & 7,0--19,8
\linebreak14,4 (3) & 20,0--36,0
\linebreak25,3 (3) & —
 \\ 
 &  & juv & 0,2--2,3
\linebreak0,5 (19) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
\\


5-й & Длина, мм & Самцы & —
 & 71,7--108,2
\linebreak91,3 (32) & 87,3--140,0
\linebreak110,6 (39) & 105,6--149,4
\linebreak126,8 (7) & 130,4--160,9
\linebreak149,6 (5) & 166,2 (1) & —
 \\ 
 &  & Самки & —
 & 80,2--105,4
\linebreak93,2 (30) & 93,6--152,9
\linebreak114,0 (48) & 123,0--147,1
\linebreak136,3 (12) & 144,2--147,0
\linebreak145,6 (2) & 140,7--179,6
\linebreak160,1 (2) & —
 \\ 
 &  & juv & 43,0--99,5
\linebreak73,1(47) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
 & Масса, г & Самцы & —
 & 1,0--4,7
\linebreak2,6 (32) & 1,7--13,0
\linebreak4,6 (39) & 3,6--15,0
\linebreak8,37(7) & 9,1--21,0
\linebreak14,9 (5) & 11,6 (1) & —
 \\ 
 &  & Самки & —
 & 1,7--4,7
\linebreak2,9 (30) & 2,0--17,0
\linebreak5,5 (48) & 7,9--15,4
\linebreak10,9 (12) & 9,9--13,0
\linebreak11,4 (2) & 12,3--28,0
\linebreak20,1 (2) & —
 \\ 
 &  & juv & 0,2--4,2
\linebreak1,4 (47) & —
 & —
 & —
 & —
 & —
 & \multicolumn{1}{l}{—
} \\ 
 &  &  &  &  &  &  &  &  &  \\ 
\\


6-й & Длина, мм & Самцы & —
 & 61,0--147,4
\linebreak98,2 (19) & 104,1--166,3
\linebreak120,4 (27) & 119,1--189,3
\linebreak147,0 (12) & 139,0--175,4
\linebreak157,2 (3) & 176,6--215,0
\linebreak195,8 (2) & 199,1--267,0
\linebreak246,4 (5) \\ 
 &  & Самки & —
 & 78,2--139,6
\linebreak99,1 (15) & 93,3--162,4
\linebreak122,3 (23) & 119,0--177,0
\linebreak145,6 (6) & 145,8--169,7
\linebreak158,9 (4) & 203,6 (1) & 212,9 (1) \\ 
 &  & juv & 44,0--96,3
\linebreak64,4 (35) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
 & Масса, г & Самцы & —
 & 1,3--13,0
\linebreak5,0 (15) & 2,7--14,0
\linebreak5,9 (27) & 6,5--24,0
\linebreak12,0 (12) & 9,0--9,8
\linebreak9,4 (2) & 18,0--38,0
\linebreak28,0  (2) & 19,6--73,0
\linebreak49,7 (5) \\ 
 &  & Самки & —
 & 1,6--11,0
\linebreak4,4 (12) & 1,8--13,0
\linebreak6,3 (23) & 5,6--16,0
\linebreak11,3 (5) & 10,7--18,0
\linebreak13,9 (4) & 34,0 (1) & 36,0 (1) \\ 
 &  & juv & 0,2--3,0
\linebreak1,3 (35) & —
 & —
 & —
 & —
 & —
 & —
 \\ 

\\

7-й & Длина, мм & Самцы & —
 & 69,6--131,3,5
\linebreak93,4 (39) & 83,5--159,1
\linebreak116,4 (41) & 105,4--181,8
\linebreak138,8 (14) & 132,0--168,0
\linebreak153,7 (5) & 134,9--178,9
\linebreak156,9 (2) & 193,5 (1) \\ 
 &  & Самки & —
 & 64,9--133,0
\linebreak88,2 (31) & 83,3--169,1
\linebreak121,6 (39) & 95,2--168,4
\linebreak136,9 (20) & 136,0--183,8
\linebreak158,8 (5) & 163,1--202,0
\linebreak177,1 (3) & 200,0 (1) \\ 
 &  & juv & 39,1--93,1
\linebreak61,3 (150) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
 & Масса, г & Самцы & —
 & 1,0--9,0
\linebreak3,0 (39) & 1,8--17,0
\linebreak6,3 (41) & 4,1--34,0
\linebreak12,1 (14) & 8,4--21,7
\linebreak15,2 (5) & 9,1--22,0
\linebreak15,5 (2) & 39,0 (1) \\ 
 &  & Самки & — & 1,0--8,7
\linebreak2,3 (31) & 1,7--22,0
\linebreak7,6 (39) & 4,0--24,0
\linebreak11,3 (20) & 9,0--26,0
\linebreak17,6 (5) & 15,0--39,0
\linebreak23,5 (3) & 51,0 (1)
 \\ 
 &  & juv & 0,1--3,5
\linebreak0,8(150) & —
 & —
 & —
 & —
 & —
 & —
 \\
\\ 

Общее & Длина, мм & Самцы & —
 & 61,0--147,4
\linebreak93,6 (133) & 83,5--166,3
\linebreak115,5 (119) & 105,4--189,3
\linebreak140,4 (45) & 130,4--181,1
\linebreak153,9 (18) & 134,9--215,0
\linebreak178,9 (9) & 175,4--267,0
\linebreak221,1 (10) \\ 
 &  & Самки & —
 & 64,9--139,6
\linebreak93,5 (100) & 83,3--169,1
\linebreak119,7 (124) & 95,2--177,0
\linebreak139,1 (48) & 134,2--183,8
\linebreak157,4 (15) & 140,7--222,6
\linebreak182,8 (11) & 170,2--212,9
\linebreak194,4 (3) \\ 
 &  & juv & 39,1--99,5
\linebreak61,8 (337) & —
 & —
 & —
 & —
 & —
 & —
 \\ 
 & Масса, г & Самцы & —
 & 1,0--13,0
\linebreak3,1 (129) & 1,7--17,0
\linebreak5,8 (119) & 3,6 -34,0
\linebreak11,0  (45) & 8,4--23,0
\linebreak14,5 (17) & 9,1--38,0
\linebreak21,3 (9) & 17,0--73,0
\linebreak39,4 (9) \\ 
 &  & Самки & —
 & 1,0--11,0
\linebreak2,9  (97) & 1,7--22,0
\linebreak6,6  (124) & 4,0--26,0
\linebreak11,5 (47) & 7,0--26,0
\linebreak14,8 (15) & 12,3--39,0
\linebreak26,7 (11) & 18,5--51,0
\linebreak35,1 (3) \\ 
 &  & juv & 0,1--4,2
\linebreak0,9 (337) & —
 & —
 & —
 & —
 & —
 & —
 \\ 

\end{longtabu}
\end{landscape}


\end{document}
  • Use \ifnum\c@page\@someconstant\relax...\else...\fi where \@someconstant is a constant (integer). – Andrew Sep 24 '14 at 0:32
  • Thank you for anwer. And how can I define my constant? \def\someconstant{236}? or there is another way? – Mihail Kondratyev Sep 24 '14 at 0:40
  • I don't think this is the best approach for a LaTeX document. Rather than using \def, for example, it would be safer to use \newcommand or \renewcommand. In any case, please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. A complete, small document people can compile is much more useful than a mere fragment of code. – cfr Sep 24 '14 at 0:41
  • I tried this: \newcommand{\someconstant}{4} \newcommand{\Endd}{End} \def\LT@head{\ifnum\c@page\@someconstant\relax\Endd\else\LT@head\fi} But it fails. pdfLates said ! Undefined control sequence. – Mihail Kondratyev Sep 24 '14 at 0:46
  • I think you need \newcommand{\@someconstant}{4}. – Peter Grill Sep 24 '14 at 0:52
4

This answer is more general in terms of your question: How to check for the page number being something specific; not just odd?

Use refcount.

Why? When you're talking about page numbers you have to remember that TeX's page builder is asynchronous, and you could end up testing for a page number that you're actually not on. As such, using references is the best way to achieve the correct page number. And when you're wanting to compare reference counters, refcount does the job.

enter image description here

\documentclass{article}
\usepackage{refcount,lipsum}
\begin{document}
Label \verb|abc| is on page~\pageref{abc}.
\ifnum\getpagerefnumber{abc}=5
  True
\else
  False
\fi

\lipsum[1-25]
\label{abc}
\lipsum[26-50]
\end{document}

After the first compilation, the reference is not yet available, and \getpagerefnumber{<label>} defaults to 0. So for the correct output, you need compile at least twice on the first go, after which the references would just have to be settled in order for the condition to be evaluated properly. Regardless, LaTeX will warn of any reference issues, if they exist.

  • Thank you for suggestion. I definitely will use it, but in my particular situation it won't help. But, anyway, I recieve an answer. – Mihail Kondratyev Sep 24 '14 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.