Self-defined table template
When I write the template below, where:
- the first parameter has been designed for optional headers:
- the second has been designed to pass to tabularx.
I get the following error: Forbidden control sequence found while scanning use of @tempc. end{extabularx}
newenvironment{extabularx}[2]{%
rowcolors{1}{gray!25}{white}%
rownum=0%
tabularx{linewidth}{#2}%
toprule%
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
}{%
bottomrule%
endtabularx%
}
Without IF statements it works fine, while with the if or ifx or ifthenelse statements it doesn't work.
tables environments
|
show 4 more comments
When I write the template below, where:
- the first parameter has been designed for optional headers:
- the second has been designed to pass to tabularx.
I get the following error: Forbidden control sequence found while scanning use of @tempc. end{extabularx}
newenvironment{extabularx}[2]{%
rowcolors{1}{gray!25}{white}%
rownum=0%
tabularx{linewidth}{#2}%
toprule%
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
}{%
bottomrule%
endtabularx%
}
Without IF statements it works fine, while with the if or ifx or ifthenelse statements it doesn't work.
tables environments
1
You're beginning anif- statement in one table cell and try to finish it in another one, either by using&in#1or ultimately, whentabularnewlineis issued. This can't work, at least not this way
– Christian Hupfer
Jan 6 at 10:10
@ChristianHupfer, Exists another way?
– BnG
Jan 6 at 10:12
Yes, Black TeX Magic ... withnoalignand constructing a token list containing theif....test and then inserting the whole token list as first table row. There are examples of this here at TeX.SE
– Christian Hupfer
Jan 6 at 10:16
Latex is really complicated. With C there are less problems :-)
– BnG
Jan 6 at 10:17
1
Not if you try to do everything with preprocessor directives which would be closer to TeX processing than this strange language ;)
– TeXnician
Jan 6 at 10:18
|
show 4 more comments
When I write the template below, where:
- the first parameter has been designed for optional headers:
- the second has been designed to pass to tabularx.
I get the following error: Forbidden control sequence found while scanning use of @tempc. end{extabularx}
newenvironment{extabularx}[2]{%
rowcolors{1}{gray!25}{white}%
rownum=0%
tabularx{linewidth}{#2}%
toprule%
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
}{%
bottomrule%
endtabularx%
}
Without IF statements it works fine, while with the if or ifx or ifthenelse statements it doesn't work.
tables environments
When I write the template below, where:
- the first parameter has been designed for optional headers:
- the second has been designed to pass to tabularx.
I get the following error: Forbidden control sequence found while scanning use of @tempc. end{extabularx}
newenvironment{extabularx}[2]{%
rowcolors{1}{gray!25}{white}%
rownum=0%
tabularx{linewidth}{#2}%
toprule%
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
}{%
bottomrule%
endtabularx%
}
Without IF statements it works fine, while with the if or ifx or ifthenelse statements it doesn't work.
tables environments
tables environments
edited Jan 6 at 10:12
BnG
asked Jan 6 at 10:05
BnGBnG
296
296
1
You're beginning anif- statement in one table cell and try to finish it in another one, either by using&in#1or ultimately, whentabularnewlineis issued. This can't work, at least not this way
– Christian Hupfer
Jan 6 at 10:10
@ChristianHupfer, Exists another way?
– BnG
Jan 6 at 10:12
Yes, Black TeX Magic ... withnoalignand constructing a token list containing theif....test and then inserting the whole token list as first table row. There are examples of this here at TeX.SE
– Christian Hupfer
Jan 6 at 10:16
Latex is really complicated. With C there are less problems :-)
– BnG
Jan 6 at 10:17
1
Not if you try to do everything with preprocessor directives which would be closer to TeX processing than this strange language ;)
– TeXnician
Jan 6 at 10:18
|
show 4 more comments
1
You're beginning anif- statement in one table cell and try to finish it in another one, either by using&in#1or ultimately, whentabularnewlineis issued. This can't work, at least not this way
– Christian Hupfer
Jan 6 at 10:10
@ChristianHupfer, Exists another way?
– BnG
Jan 6 at 10:12
Yes, Black TeX Magic ... withnoalignand constructing a token list containing theif....test and then inserting the whole token list as first table row. There are examples of this here at TeX.SE
– Christian Hupfer
Jan 6 at 10:16
Latex is really complicated. With C there are less problems :-)
– BnG
Jan 6 at 10:17
1
Not if you try to do everything with preprocessor directives which would be closer to TeX processing than this strange language ;)
– TeXnician
Jan 6 at 10:18
1
1
You're beginning an
if - statement in one table cell and try to finish it in another one, either by using & in #1 or ultimately, when tabularnewline is issued. This can't work, at least not this way– Christian Hupfer
Jan 6 at 10:10
You're beginning an
if - statement in one table cell and try to finish it in another one, either by using & in #1 or ultimately, when tabularnewline is issued. This can't work, at least not this way– Christian Hupfer
Jan 6 at 10:10
@ChristianHupfer, Exists another way?
– BnG
Jan 6 at 10:12
@ChristianHupfer, Exists another way?
– BnG
Jan 6 at 10:12
Yes, Black TeX Magic ... with
noalign and constructing a token list containing the if.... test and then inserting the whole token list as first table row. There are examples of this here at TeX.SE– Christian Hupfer
Jan 6 at 10:16
Yes, Black TeX Magic ... with
noalign and constructing a token list containing the if.... test and then inserting the whole token list as first table row. There are examples of this here at TeX.SE– Christian Hupfer
Jan 6 at 10:16
Latex is really complicated. With C there are less problems :-)
– BnG
Jan 6 at 10:17
Latex is really complicated. With C there are less problems :-)
– BnG
Jan 6 at 10:17
1
1
Not if you try to do everything with preprocessor directives which would be closer to TeX processing than this strange language ;)
– TeXnician
Jan 6 at 10:18
Not if you try to do everything with preprocessor directives which would be closer to TeX processing than this strange language ;)
– TeXnician
Jan 6 at 10:18
|
show 4 more comments
1 Answer
1
active
oldest
votes
As you have provided no test file or example of how the command is used it is hard to help in detail but
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
This is syntactically correct but tests if the first token in #1 is the token empty
if it is, that token is removed but remaining tokens of # are executed, followed by relax. If #1 does not start with empty then it typesets a ( followed by rowcolor which will always give an error as it has to be the first command in the row, but is following ( here.
That was probably not the test intended (you mention it doesn't work but leave us to guess what you wanted it to do)
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
ifthenelse does not work via expansion so you do not want to use this here. the test clause with empty is wrong but even if that were fixed, you would not be able to use rowcolor or multicolumn etc that need to be at the start of the row.
Possibly you want to replace all of the code I highlighted by
ifrelaxdetokenize{#1}relax
expandafter@gobble
else
expandafter@firstofone
fi
{rowcolor{gray!50} #1tabularnewlinemidrule}%
assuming @ is a letter when you make the definitiuon (so in a package or after makeatletter in the preamble)
That would use an expandable test to check if #1 is empty, and use it to make a grey heading row if not empty.
No TeX Black Magic withnoalignhere?
– Christian Hupfer
Jan 6 at 17:26
@ChristianHupfer that is supplied byrowcolor
– David Carlisle
Jan 6 at 17:31
I see. Thank you very much.
– Christian Hupfer
Jan 6 at 18:56
@DavidCarlisle I have no words. It's incomprehensible, for now, but it works! The next step is to understand what this macro does and how usingexpandafter. Thanks.
– BnG
Jan 7 at 21:05
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468807%2fself-defined-table-template%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As you have provided no test file or example of how the command is used it is hard to help in detail but
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
This is syntactically correct but tests if the first token in #1 is the token empty
if it is, that token is removed but remaining tokens of # are executed, followed by relax. If #1 does not start with empty then it typesets a ( followed by rowcolor which will always give an error as it has to be the first command in the row, but is following ( here.
That was probably not the test intended (you mention it doesn't work but leave us to guess what you wanted it to do)
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
ifthenelse does not work via expansion so you do not want to use this here. the test clause with empty is wrong but even if that were fixed, you would not be able to use rowcolor or multicolumn etc that need to be at the start of the row.
Possibly you want to replace all of the code I highlighted by
ifrelaxdetokenize{#1}relax
expandafter@gobble
else
expandafter@firstofone
fi
{rowcolor{gray!50} #1tabularnewlinemidrule}%
assuming @ is a letter when you make the definitiuon (so in a package or after makeatletter in the preamble)
That would use an expandable test to check if #1 is empty, and use it to make a grey heading row if not empty.
No TeX Black Magic withnoalignhere?
– Christian Hupfer
Jan 6 at 17:26
@ChristianHupfer that is supplied byrowcolor
– David Carlisle
Jan 6 at 17:31
I see. Thank you very much.
– Christian Hupfer
Jan 6 at 18:56
@DavidCarlisle I have no words. It's incomprehensible, for now, but it works! The next step is to understand what this macro does and how usingexpandafter. Thanks.
– BnG
Jan 7 at 21:05
add a comment |
As you have provided no test file or example of how the command is used it is hard to help in detail but
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
This is syntactically correct but tests if the first token in #1 is the token empty
if it is, that token is removed but remaining tokens of # are executed, followed by relax. If #1 does not start with empty then it typesets a ( followed by rowcolor which will always give an error as it has to be the first command in the row, but is following ( here.
That was probably not the test intended (you mention it doesn't work but leave us to guess what you wanted it to do)
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
ifthenelse does not work via expansion so you do not want to use this here. the test clause with empty is wrong but even if that were fixed, you would not be able to use rowcolor or multicolumn etc that need to be at the start of the row.
Possibly you want to replace all of the code I highlighted by
ifrelaxdetokenize{#1}relax
expandafter@gobble
else
expandafter@firstofone
fi
{rowcolor{gray!50} #1tabularnewlinemidrule}%
assuming @ is a letter when you make the definitiuon (so in a package or after makeatletter in the preamble)
That would use an expandable test to check if #1 is empty, and use it to make a grey heading row if not empty.
No TeX Black Magic withnoalignhere?
– Christian Hupfer
Jan 6 at 17:26
@ChristianHupfer that is supplied byrowcolor
– David Carlisle
Jan 6 at 17:31
I see. Thank you very much.
– Christian Hupfer
Jan 6 at 18:56
@DavidCarlisle I have no words. It's incomprehensible, for now, but it works! The next step is to understand what this macro does and how usingexpandafter. Thanks.
– BnG
Jan 7 at 21:05
add a comment |
As you have provided no test file or example of how the command is used it is hard to help in detail but
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
This is syntactically correct but tests if the first token in #1 is the token empty
if it is, that token is removed but remaining tokens of # are executed, followed by relax. If #1 does not start with empty then it typesets a ( followed by rowcolor which will always give an error as it has to be the first command in the row, but is following ( here.
That was probably not the test intended (you mention it doesn't work but leave us to guess what you wanted it to do)
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
ifthenelse does not work via expansion so you do not want to use this here. the test clause with empty is wrong but even if that were fixed, you would not be able to use rowcolor or multicolumn etc that need to be at the start of the row.
Possibly you want to replace all of the code I highlighted by
ifrelaxdetokenize{#1}relax
expandafter@gobble
else
expandafter@firstofone
fi
{rowcolor{gray!50} #1tabularnewlinemidrule}%
assuming @ is a letter when you make the definitiuon (so in a package or after makeatletter in the preamble)
That would use an expandable test to check if #1 is empty, and use it to make a grey heading row if not empty.
As you have provided no test file or example of how the command is used it is hard to help in detail but
%ifxempty#1relaxelse(rowcolor{gray!50} #1tabularnewline)fi%
This is syntactically correct but tests if the first token in #1 is the token empty
if it is, that token is removed but remaining tokens of # are executed, followed by relax. If #1 does not start with empty then it typesets a ( followed by rowcolor which will always give an error as it has to be the first command in the row, but is following ( here.
That was probably not the test intended (you mention it doesn't work but leave us to guess what you wanted it to do)
ifthenelse{empty#1}{%
relax
}{%
rowcolor{gray!50}%
#1tabularnewline%
midrule%
}%
ifthenelse does not work via expansion so you do not want to use this here. the test clause with empty is wrong but even if that were fixed, you would not be able to use rowcolor or multicolumn etc that need to be at the start of the row.
Possibly you want to replace all of the code I highlighted by
ifrelaxdetokenize{#1}relax
expandafter@gobble
else
expandafter@firstofone
fi
{rowcolor{gray!50} #1tabularnewlinemidrule}%
assuming @ is a letter when you make the definitiuon (so in a package or after makeatletter in the preamble)
That would use an expandable test to check if #1 is empty, and use it to make a grey heading row if not empty.
answered Jan 6 at 14:58
David CarlisleDavid Carlisle
485k4111201863
485k4111201863
No TeX Black Magic withnoalignhere?
– Christian Hupfer
Jan 6 at 17:26
@ChristianHupfer that is supplied byrowcolor
– David Carlisle
Jan 6 at 17:31
I see. Thank you very much.
– Christian Hupfer
Jan 6 at 18:56
@DavidCarlisle I have no words. It's incomprehensible, for now, but it works! The next step is to understand what this macro does and how usingexpandafter. Thanks.
– BnG
Jan 7 at 21:05
add a comment |
No TeX Black Magic withnoalignhere?
– Christian Hupfer
Jan 6 at 17:26
@ChristianHupfer that is supplied byrowcolor
– David Carlisle
Jan 6 at 17:31
I see. Thank you very much.
– Christian Hupfer
Jan 6 at 18:56
@DavidCarlisle I have no words. It's incomprehensible, for now, but it works! The next step is to understand what this macro does and how usingexpandafter. Thanks.
– BnG
Jan 7 at 21:05
No TeX Black Magic with
noalign here?– Christian Hupfer
Jan 6 at 17:26
No TeX Black Magic with
noalign here?– Christian Hupfer
Jan 6 at 17:26
@ChristianHupfer that is supplied by
rowcolor– David Carlisle
Jan 6 at 17:31
@ChristianHupfer that is supplied by
rowcolor– David Carlisle
Jan 6 at 17:31
I see. Thank you very much.
– Christian Hupfer
Jan 6 at 18:56
I see. Thank you very much.
– Christian Hupfer
Jan 6 at 18:56
@DavidCarlisle I have no words. It's incomprehensible, for now, but it works! The next step is to understand what this macro does and how using
expandafter. Thanks.– BnG
Jan 7 at 21:05
@DavidCarlisle I have no words. It's incomprehensible, for now, but it works! The next step is to understand what this macro does and how using
expandafter. Thanks.– BnG
Jan 7 at 21:05
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468807%2fself-defined-table-template%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You're beginning an
if- statement in one table cell and try to finish it in another one, either by using&in#1or ultimately, whentabularnewlineis issued. This can't work, at least not this way– Christian Hupfer
Jan 6 at 10:10
@ChristianHupfer, Exists another way?
– BnG
Jan 6 at 10:12
Yes, Black TeX Magic ... with
noalignand constructing a token list containing theif....test and then inserting the whole token list as first table row. There are examples of this here at TeX.SE– Christian Hupfer
Jan 6 at 10:16
Latex is really complicated. With C there are less problems :-)
– BnG
Jan 6 at 10:17
1
Not if you try to do everything with preprocessor directives which would be closer to TeX processing than this strange language ;)
– TeXnician
Jan 6 at 10:18