Use comma instead of & in table
I am new in LaTeX. In tabular
, we generally use &
for partition. I want to create a .sty
for tabular environment. Replace &
with comma delimiter, in this case comma should be work as &
like in tabular
command.
In .tex
file, input is a,b,c
and output should look like |a|b|c|
tables tex-core
New contributor
|
show 2 more comments
I am new in LaTeX. In tabular
, we generally use &
for partition. I want to create a .sty
for tabular environment. Replace &
with comma delimiter, in this case comma should be work as &
like in tabular
command.
In .tex
file, input is a,b,c
and output should look like |a|b|c|
tables tex-core
New contributor
5
I strongly recommend not to do that, because it is extremely complicated. Firstly you have to understand the definition oftabular
inlatex.ltx
. That is a real problem.
– JouleV
yesterday
4
I do not which use you would do of this convention, but how would you fiddle with cells that should contain commas? If it is for special types of tabulars, you might want to take a look at thecsvsimple
package, or the more powerfuldatatool
.
– Bernard
23 hours ago
1
@Bernard Can't you say the same about the default syntax: how would you fiddle with cells that should contain&
s? Ultimately it depends on the nature of the data whether commas or ampersands are more common in the cells. (I'm not recommending trying to achieve the OP's goal in LaTeX -- my preference would be to run a preprocessor on the comma-separated data to produce valid LaTeX syntax -- just pointing out that the LaTeX syntax just happens to be what Knuth/Lamport decided to adopt for their use-cases, and isn't objectively better for all applications.)
– ShreevatsaR
20 hours ago
You have to escape the ampersand to print it (&
)whereas for the comma you can't . Also, using a comma is certainly mor commen (for instance if a cell contains a list, or the decimal comma for numeric values – not all countries use a dot for that.
– Bernard
20 hours ago
1
@Bernard There is no intrinsic difference between&
and ,` except that the former happens to have an appropriate definition in LaTeX by default, and the latter doesn't (and would have to be redefined after finding a new name for what is currently,
). And yes, commas may indeed be more common in many/most "typical" applications, but we don't know what's more common in the OP's application. Question is whether to bend the tool for the sake of our task or vice-versa… IMO the only reason for preferring&
here is because LaTeX is more suited for it, not anything intrinsic to the syntax.
– ShreevatsaR
16 hours ago
|
show 2 more comments
I am new in LaTeX. In tabular
, we generally use &
for partition. I want to create a .sty
for tabular environment. Replace &
with comma delimiter, in this case comma should be work as &
like in tabular
command.
In .tex
file, input is a,b,c
and output should look like |a|b|c|
tables tex-core
New contributor
I am new in LaTeX. In tabular
, we generally use &
for partition. I want to create a .sty
for tabular environment. Replace &
with comma delimiter, in this case comma should be work as &
like in tabular
command.
In .tex
file, input is a,b,c
and output should look like |a|b|c|
tables tex-core
tables tex-core
New contributor
New contributor
edited yesterday
JouleV
4,80611039
4,80611039
New contributor
asked yesterday
limlianlimlian
411
411
New contributor
New contributor
5
I strongly recommend not to do that, because it is extremely complicated. Firstly you have to understand the definition oftabular
inlatex.ltx
. That is a real problem.
– JouleV
yesterday
4
I do not which use you would do of this convention, but how would you fiddle with cells that should contain commas? If it is for special types of tabulars, you might want to take a look at thecsvsimple
package, or the more powerfuldatatool
.
– Bernard
23 hours ago
1
@Bernard Can't you say the same about the default syntax: how would you fiddle with cells that should contain&
s? Ultimately it depends on the nature of the data whether commas or ampersands are more common in the cells. (I'm not recommending trying to achieve the OP's goal in LaTeX -- my preference would be to run a preprocessor on the comma-separated data to produce valid LaTeX syntax -- just pointing out that the LaTeX syntax just happens to be what Knuth/Lamport decided to adopt for their use-cases, and isn't objectively better for all applications.)
– ShreevatsaR
20 hours ago
You have to escape the ampersand to print it (&
)whereas for the comma you can't . Also, using a comma is certainly mor commen (for instance if a cell contains a list, or the decimal comma for numeric values – not all countries use a dot for that.
– Bernard
20 hours ago
1
@Bernard There is no intrinsic difference between&
and ,` except that the former happens to have an appropriate definition in LaTeX by default, and the latter doesn't (and would have to be redefined after finding a new name for what is currently,
). And yes, commas may indeed be more common in many/most "typical" applications, but we don't know what's more common in the OP's application. Question is whether to bend the tool for the sake of our task or vice-versa… IMO the only reason for preferring&
here is because LaTeX is more suited for it, not anything intrinsic to the syntax.
– ShreevatsaR
16 hours ago
|
show 2 more comments
5
I strongly recommend not to do that, because it is extremely complicated. Firstly you have to understand the definition oftabular
inlatex.ltx
. That is a real problem.
– JouleV
yesterday
4
I do not which use you would do of this convention, but how would you fiddle with cells that should contain commas? If it is for special types of tabulars, you might want to take a look at thecsvsimple
package, or the more powerfuldatatool
.
– Bernard
23 hours ago
1
@Bernard Can't you say the same about the default syntax: how would you fiddle with cells that should contain&
s? Ultimately it depends on the nature of the data whether commas or ampersands are more common in the cells. (I'm not recommending trying to achieve the OP's goal in LaTeX -- my preference would be to run a preprocessor on the comma-separated data to produce valid LaTeX syntax -- just pointing out that the LaTeX syntax just happens to be what Knuth/Lamport decided to adopt for their use-cases, and isn't objectively better for all applications.)
– ShreevatsaR
20 hours ago
You have to escape the ampersand to print it (&
)whereas for the comma you can't . Also, using a comma is certainly mor commen (for instance if a cell contains a list, or the decimal comma for numeric values – not all countries use a dot for that.
– Bernard
20 hours ago
1
@Bernard There is no intrinsic difference between&
and ,` except that the former happens to have an appropriate definition in LaTeX by default, and the latter doesn't (and would have to be redefined after finding a new name for what is currently,
). And yes, commas may indeed be more common in many/most "typical" applications, but we don't know what's more common in the OP's application. Question is whether to bend the tool for the sake of our task or vice-versa… IMO the only reason for preferring&
here is because LaTeX is more suited for it, not anything intrinsic to the syntax.
– ShreevatsaR
16 hours ago
5
5
I strongly recommend not to do that, because it is extremely complicated. Firstly you have to understand the definition of
tabular
in latex.ltx
. That is a real problem.– JouleV
yesterday
I strongly recommend not to do that, because it is extremely complicated. Firstly you have to understand the definition of
tabular
in latex.ltx
. That is a real problem.– JouleV
yesterday
4
4
I do not which use you would do of this convention, but how would you fiddle with cells that should contain commas? If it is for special types of tabulars, you might want to take a look at the
csvsimple
package, or the more powerful datatool
.– Bernard
23 hours ago
I do not which use you would do of this convention, but how would you fiddle with cells that should contain commas? If it is for special types of tabulars, you might want to take a look at the
csvsimple
package, or the more powerful datatool
.– Bernard
23 hours ago
1
1
@Bernard Can't you say the same about the default syntax: how would you fiddle with cells that should contain
&
s? Ultimately it depends on the nature of the data whether commas or ampersands are more common in the cells. (I'm not recommending trying to achieve the OP's goal in LaTeX -- my preference would be to run a preprocessor on the comma-separated data to produce valid LaTeX syntax -- just pointing out that the LaTeX syntax just happens to be what Knuth/Lamport decided to adopt for their use-cases, and isn't objectively better for all applications.)– ShreevatsaR
20 hours ago
@Bernard Can't you say the same about the default syntax: how would you fiddle with cells that should contain
&
s? Ultimately it depends on the nature of the data whether commas or ampersands are more common in the cells. (I'm not recommending trying to achieve the OP's goal in LaTeX -- my preference would be to run a preprocessor on the comma-separated data to produce valid LaTeX syntax -- just pointing out that the LaTeX syntax just happens to be what Knuth/Lamport decided to adopt for their use-cases, and isn't objectively better for all applications.)– ShreevatsaR
20 hours ago
You have to escape the ampersand to print it (
&
)whereas for the comma you can't . Also, using a comma is certainly mor commen (for instance if a cell contains a list, or the decimal comma for numeric values – not all countries use a dot for that.– Bernard
20 hours ago
You have to escape the ampersand to print it (
&
)whereas for the comma you can't . Also, using a comma is certainly mor commen (for instance if a cell contains a list, or the decimal comma for numeric values – not all countries use a dot for that.– Bernard
20 hours ago
1
1
@Bernard There is no intrinsic difference between
&
and ,` except that the former happens to have an appropriate definition in LaTeX by default, and the latter doesn't (and would have to be redefined after finding a new name for what is currently ,
). And yes, commas may indeed be more common in many/most "typical" applications, but we don't know what's more common in the OP's application. Question is whether to bend the tool for the sake of our task or vice-versa… IMO the only reason for preferring &
here is because LaTeX is more suited for it, not anything intrinsic to the syntax.– ShreevatsaR
16 hours ago
@Bernard There is no intrinsic difference between
&
and ,` except that the former happens to have an appropriate definition in LaTeX by default, and the latter doesn't (and would have to be redefined after finding a new name for what is currently ,
). And yes, commas may indeed be more common in many/most "typical" applications, but we don't know what's more common in the OP's application. Question is whether to bend the tool for the sake of our task or vice-versa… IMO the only reason for preferring &
here is because LaTeX is more suited for it, not anything intrinsic to the syntax.– ShreevatsaR
16 hours ago
|
show 2 more comments
3 Answers
3
active
oldest
votes
Proof of concept. Use at your own risk!
The basic approach is to change catcode
of the character you want to use as “alignment tab”. Here's a mytabular
environment which does that:
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff
begin{document}
pagestyle{empty}
begin{mytabular}{l|r}
a , b & c \
c , d \
end{mytabular}
begin{mytabular}[@]{l|r}
a @ b \
c @ d, & e \
end{mytabular}
end{document}
The optional argument lets you choose which character is used as alignment tab. No verification whatsoever is done to see if the character you passed is valid. If you don't pass a character, a comma is used. The &
behaves as a normal character.
However, as other already warned you, this is not the best idea. Packages that rely on &
being an alignment tab will break.
Thank you so much for your reply.
– limlian
7 hours ago
@limlian TeX doesn't allow you more than 9 parameters. You'd have to find another way around to use 12. But in your example you used only 6 parameter (non consecutive). But I think that 12 is far from user friendly and I would suggest another approach, if you specified your use case. However, try the code I proposed withbegin{mytabular}{|c|c|c|} a, b, c \ x, y, z \ end{mytabular}
. It seem to do as you want.
– Phelype Oleinik
2 hours ago
@limlian Please, add to your question, not to comments to an answer. But I believe that a new question, with better specification of your problem is what you should do.
– egreg
2 hours ago
add a comment |
As Bernard suggested, why don't use csvsimple
?
If you have commas in your cells, just put the contents within curly brackets.
If you have & in your cells, just write &
.
documentclass{article}
usepackage{filecontents}
usepackage{csvsimple}
begin{document}
begin{filecontents*}{mydata.csv}
a,b,c
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
vspace{3ex}
and if you have commas or & in your cells:
vspace{3ex}
begin{filecontents*}{mydata.csv}
a,b,c
{c, d},{e, f, g},{h, i, j, k}
l & m,{n & o, p},q & r & s & t
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
end{document}
add a comment |
You can use the spalign
package (documentation here), which includes spaligntabular
that acts exactly like tabular, except it uses both space and comma as the align character &
and semicolon as the the end-of-row control
sequence \
:
documentclass[12pt]{report}
usepackage{spalign}
begin{document}
spaligntabular{lcr}{a b c; aa bb cc}
spaligntabular{|c|c|c}{a,b,c}
end{document}
It produces this:
and
The spalign
package also includes similar commands, such as spalignmat
for a matrix and spalignarray
for a generic array.
There are options to use different characters instead of or in addition to space, comma, and semicolon (see the documentation).
By the way, if you need to include a comma, space, or semicolon in your table, just enclose it in braces {}
.
2
I didn't know this package, I think it does exactly what the OP wants, +1!
– CarLaTeX
8 hours ago
Absolutely I agree with @CarLaTeX :-) Very good.
– Sebastiano
2 hours ago
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
});
}
});
limlian is a new contributor. Be nice, and check out our Code of Conduct.
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%2f477714%2fuse-comma-instead-of-in-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Proof of concept. Use at your own risk!
The basic approach is to change catcode
of the character you want to use as “alignment tab”. Here's a mytabular
environment which does that:
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff
begin{document}
pagestyle{empty}
begin{mytabular}{l|r}
a , b & c \
c , d \
end{mytabular}
begin{mytabular}[@]{l|r}
a @ b \
c @ d, & e \
end{mytabular}
end{document}
The optional argument lets you choose which character is used as alignment tab. No verification whatsoever is done to see if the character you passed is valid. If you don't pass a character, a comma is used. The &
behaves as a normal character.
However, as other already warned you, this is not the best idea. Packages that rely on &
being an alignment tab will break.
Thank you so much for your reply.
– limlian
7 hours ago
@limlian TeX doesn't allow you more than 9 parameters. You'd have to find another way around to use 12. But in your example you used only 6 parameter (non consecutive). But I think that 12 is far from user friendly and I would suggest another approach, if you specified your use case. However, try the code I proposed withbegin{mytabular}{|c|c|c|} a, b, c \ x, y, z \ end{mytabular}
. It seem to do as you want.
– Phelype Oleinik
2 hours ago
@limlian Please, add to your question, not to comments to an answer. But I believe that a new question, with better specification of your problem is what you should do.
– egreg
2 hours ago
add a comment |
Proof of concept. Use at your own risk!
The basic approach is to change catcode
of the character you want to use as “alignment tab”. Here's a mytabular
environment which does that:
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff
begin{document}
pagestyle{empty}
begin{mytabular}{l|r}
a , b & c \
c , d \
end{mytabular}
begin{mytabular}[@]{l|r}
a @ b \
c @ d, & e \
end{mytabular}
end{document}
The optional argument lets you choose which character is used as alignment tab. No verification whatsoever is done to see if the character you passed is valid. If you don't pass a character, a comma is used. The &
behaves as a normal character.
However, as other already warned you, this is not the best idea. Packages that rely on &
being an alignment tab will break.
Thank you so much for your reply.
– limlian
7 hours ago
@limlian TeX doesn't allow you more than 9 parameters. You'd have to find another way around to use 12. But in your example you used only 6 parameter (non consecutive). But I think that 12 is far from user friendly and I would suggest another approach, if you specified your use case. However, try the code I proposed withbegin{mytabular}{|c|c|c|} a, b, c \ x, y, z \ end{mytabular}
. It seem to do as you want.
– Phelype Oleinik
2 hours ago
@limlian Please, add to your question, not to comments to an answer. But I believe that a new question, with better specification of your problem is what you should do.
– egreg
2 hours ago
add a comment |
Proof of concept. Use at your own risk!
The basic approach is to change catcode
of the character you want to use as “alignment tab”. Here's a mytabular
environment which does that:
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff
begin{document}
pagestyle{empty}
begin{mytabular}{l|r}
a , b & c \
c , d \
end{mytabular}
begin{mytabular}[@]{l|r}
a @ b \
c @ d, & e \
end{mytabular}
end{document}
The optional argument lets you choose which character is used as alignment tab. No verification whatsoever is done to see if the character you passed is valid. If you don't pass a character, a comma is used. The &
behaves as a normal character.
However, as other already warned you, this is not the best idea. Packages that rely on &
being an alignment tab will break.
Proof of concept. Use at your own risk!
The basic approach is to change catcode
of the character you want to use as “alignment tab”. Here's a mytabular
environment which does that:
documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff
begin{document}
pagestyle{empty}
begin{mytabular}{l|r}
a , b & c \
c , d \
end{mytabular}
begin{mytabular}[@]{l|r}
a @ b \
c @ d, & e \
end{mytabular}
end{document}
The optional argument lets you choose which character is used as alignment tab. No verification whatsoever is done to see if the character you passed is valid. If you don't pass a character, a comma is used. The &
behaves as a normal character.
However, as other already warned you, this is not the best idea. Packages that rely on &
being an alignment tab will break.
edited 2 hours ago
answered 23 hours ago
Phelype OleinikPhelype Oleinik
23.8k54587
23.8k54587
Thank you so much for your reply.
– limlian
7 hours ago
@limlian TeX doesn't allow you more than 9 parameters. You'd have to find another way around to use 12. But in your example you used only 6 parameter (non consecutive). But I think that 12 is far from user friendly and I would suggest another approach, if you specified your use case. However, try the code I proposed withbegin{mytabular}{|c|c|c|} a, b, c \ x, y, z \ end{mytabular}
. It seem to do as you want.
– Phelype Oleinik
2 hours ago
@limlian Please, add to your question, not to comments to an answer. But I believe that a new question, with better specification of your problem is what you should do.
– egreg
2 hours ago
add a comment |
Thank you so much for your reply.
– limlian
7 hours ago
@limlian TeX doesn't allow you more than 9 parameters. You'd have to find another way around to use 12. But in your example you used only 6 parameter (non consecutive). But I think that 12 is far from user friendly and I would suggest another approach, if you specified your use case. However, try the code I proposed withbegin{mytabular}{|c|c|c|} a, b, c \ x, y, z \ end{mytabular}
. It seem to do as you want.
– Phelype Oleinik
2 hours ago
@limlian Please, add to your question, not to comments to an answer. But I believe that a new question, with better specification of your problem is what you should do.
– egreg
2 hours ago
Thank you so much for your reply.
– limlian
7 hours ago
Thank you so much for your reply.
– limlian
7 hours ago
@limlian TeX doesn't allow you more than 9 parameters. You'd have to find another way around to use 12. But in your example you used only 6 parameter (non consecutive). But I think that 12 is far from user friendly and I would suggest another approach, if you specified your use case. However, try the code I proposed with
begin{mytabular}{|c|c|c|} a, b, c \ x, y, z \ end{mytabular}
. It seem to do as you want.– Phelype Oleinik
2 hours ago
@limlian TeX doesn't allow you more than 9 parameters. You'd have to find another way around to use 12. But in your example you used only 6 parameter (non consecutive). But I think that 12 is far from user friendly and I would suggest another approach, if you specified your use case. However, try the code I proposed with
begin{mytabular}{|c|c|c|} a, b, c \ x, y, z \ end{mytabular}
. It seem to do as you want.– Phelype Oleinik
2 hours ago
@limlian Please, add to your question, not to comments to an answer. But I believe that a new question, with better specification of your problem is what you should do.
– egreg
2 hours ago
@limlian Please, add to your question, not to comments to an answer. But I believe that a new question, with better specification of your problem is what you should do.
– egreg
2 hours ago
add a comment |
As Bernard suggested, why don't use csvsimple
?
If you have commas in your cells, just put the contents within curly brackets.
If you have & in your cells, just write &
.
documentclass{article}
usepackage{filecontents}
usepackage{csvsimple}
begin{document}
begin{filecontents*}{mydata.csv}
a,b,c
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
vspace{3ex}
and if you have commas or & in your cells:
vspace{3ex}
begin{filecontents*}{mydata.csv}
a,b,c
{c, d},{e, f, g},{h, i, j, k}
l & m,{n & o, p},q & r & s & t
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
end{document}
add a comment |
As Bernard suggested, why don't use csvsimple
?
If you have commas in your cells, just put the contents within curly brackets.
If you have & in your cells, just write &
.
documentclass{article}
usepackage{filecontents}
usepackage{csvsimple}
begin{document}
begin{filecontents*}{mydata.csv}
a,b,c
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
vspace{3ex}
and if you have commas or & in your cells:
vspace{3ex}
begin{filecontents*}{mydata.csv}
a,b,c
{c, d},{e, f, g},{h, i, j, k}
l & m,{n & o, p},q & r & s & t
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
end{document}
add a comment |
As Bernard suggested, why don't use csvsimple
?
If you have commas in your cells, just put the contents within curly brackets.
If you have & in your cells, just write &
.
documentclass{article}
usepackage{filecontents}
usepackage{csvsimple}
begin{document}
begin{filecontents*}{mydata.csv}
a,b,c
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
vspace{3ex}
and if you have commas or & in your cells:
vspace{3ex}
begin{filecontents*}{mydata.csv}
a,b,c
{c, d},{e, f, g},{h, i, j, k}
l & m,{n & o, p},q & r & s & t
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
end{document}
As Bernard suggested, why don't use csvsimple
?
If you have commas in your cells, just put the contents within curly brackets.
If you have & in your cells, just write &
.
documentclass{article}
usepackage{filecontents}
usepackage{csvsimple}
begin{document}
begin{filecontents*}{mydata.csv}
a,b,c
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
vspace{3ex}
and if you have commas or & in your cells:
vspace{3ex}
begin{filecontents*}{mydata.csv}
a,b,c
{c, d},{e, f, g},{h, i, j, k}
l & m,{n & o, p},q & r & s & t
end{filecontents*}
csvreader[
tabular=|c|c|c|,
nohead
]{mydata.csv}% filename
{}{csvcoli & csvcolii & csvcoliii}
end{document}
edited 8 hours ago
answered 19 hours ago
CarLaTeXCarLaTeX
32.6k551135
32.6k551135
add a comment |
add a comment |
You can use the spalign
package (documentation here), which includes spaligntabular
that acts exactly like tabular, except it uses both space and comma as the align character &
and semicolon as the the end-of-row control
sequence \
:
documentclass[12pt]{report}
usepackage{spalign}
begin{document}
spaligntabular{lcr}{a b c; aa bb cc}
spaligntabular{|c|c|c}{a,b,c}
end{document}
It produces this:
and
The spalign
package also includes similar commands, such as spalignmat
for a matrix and spalignarray
for a generic array.
There are options to use different characters instead of or in addition to space, comma, and semicolon (see the documentation).
By the way, if you need to include a comma, space, or semicolon in your table, just enclose it in braces {}
.
2
I didn't know this package, I think it does exactly what the OP wants, +1!
– CarLaTeX
8 hours ago
Absolutely I agree with @CarLaTeX :-) Very good.
– Sebastiano
2 hours ago
add a comment |
You can use the spalign
package (documentation here), which includes spaligntabular
that acts exactly like tabular, except it uses both space and comma as the align character &
and semicolon as the the end-of-row control
sequence \
:
documentclass[12pt]{report}
usepackage{spalign}
begin{document}
spaligntabular{lcr}{a b c; aa bb cc}
spaligntabular{|c|c|c}{a,b,c}
end{document}
It produces this:
and
The spalign
package also includes similar commands, such as spalignmat
for a matrix and spalignarray
for a generic array.
There are options to use different characters instead of or in addition to space, comma, and semicolon (see the documentation).
By the way, if you need to include a comma, space, or semicolon in your table, just enclose it in braces {}
.
2
I didn't know this package, I think it does exactly what the OP wants, +1!
– CarLaTeX
8 hours ago
Absolutely I agree with @CarLaTeX :-) Very good.
– Sebastiano
2 hours ago
add a comment |
You can use the spalign
package (documentation here), which includes spaligntabular
that acts exactly like tabular, except it uses both space and comma as the align character &
and semicolon as the the end-of-row control
sequence \
:
documentclass[12pt]{report}
usepackage{spalign}
begin{document}
spaligntabular{lcr}{a b c; aa bb cc}
spaligntabular{|c|c|c}{a,b,c}
end{document}
It produces this:
and
The spalign
package also includes similar commands, such as spalignmat
for a matrix and spalignarray
for a generic array.
There are options to use different characters instead of or in addition to space, comma, and semicolon (see the documentation).
By the way, if you need to include a comma, space, or semicolon in your table, just enclose it in braces {}
.
You can use the spalign
package (documentation here), which includes spaligntabular
that acts exactly like tabular, except it uses both space and comma as the align character &
and semicolon as the the end-of-row control
sequence \
:
documentclass[12pt]{report}
usepackage{spalign}
begin{document}
spaligntabular{lcr}{a b c; aa bb cc}
spaligntabular{|c|c|c}{a,b,c}
end{document}
It produces this:
and
The spalign
package also includes similar commands, such as spalignmat
for a matrix and spalignarray
for a generic array.
There are options to use different characters instead of or in addition to space, comma, and semicolon (see the documentation).
By the way, if you need to include a comma, space, or semicolon in your table, just enclose it in braces {}
.
edited 11 hours ago
answered 11 hours ago
JasonVJasonV
914
914
2
I didn't know this package, I think it does exactly what the OP wants, +1!
– CarLaTeX
8 hours ago
Absolutely I agree with @CarLaTeX :-) Very good.
– Sebastiano
2 hours ago
add a comment |
2
I didn't know this package, I think it does exactly what the OP wants, +1!
– CarLaTeX
8 hours ago
Absolutely I agree with @CarLaTeX :-) Very good.
– Sebastiano
2 hours ago
2
2
I didn't know this package, I think it does exactly what the OP wants, +1!
– CarLaTeX
8 hours ago
I didn't know this package, I think it does exactly what the OP wants, +1!
– CarLaTeX
8 hours ago
Absolutely I agree with @CarLaTeX :-) Very good.
– Sebastiano
2 hours ago
Absolutely I agree with @CarLaTeX :-) Very good.
– Sebastiano
2 hours ago
add a comment |
limlian is a new contributor. Be nice, and check out our Code of Conduct.
limlian is a new contributor. Be nice, and check out our Code of Conduct.
limlian is a new contributor. Be nice, and check out our Code of Conduct.
limlian is a new contributor. Be nice, and check out our Code of Conduct.
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%2f477714%2fuse-comma-instead-of-in-table%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
5
I strongly recommend not to do that, because it is extremely complicated. Firstly you have to understand the definition of
tabular
inlatex.ltx
. That is a real problem.– JouleV
yesterday
4
I do not which use you would do of this convention, but how would you fiddle with cells that should contain commas? If it is for special types of tabulars, you might want to take a look at the
csvsimple
package, or the more powerfuldatatool
.– Bernard
23 hours ago
1
@Bernard Can't you say the same about the default syntax: how would you fiddle with cells that should contain
&
s? Ultimately it depends on the nature of the data whether commas or ampersands are more common in the cells. (I'm not recommending trying to achieve the OP's goal in LaTeX -- my preference would be to run a preprocessor on the comma-separated data to produce valid LaTeX syntax -- just pointing out that the LaTeX syntax just happens to be what Knuth/Lamport decided to adopt for their use-cases, and isn't objectively better for all applications.)– ShreevatsaR
20 hours ago
You have to escape the ampersand to print it (
&
)whereas for the comma you can't . Also, using a comma is certainly mor commen (for instance if a cell contains a list, or the decimal comma for numeric values – not all countries use a dot for that.– Bernard
20 hours ago
1
@Bernard There is no intrinsic difference between
&
and ,` except that the former happens to have an appropriate definition in LaTeX by default, and the latter doesn't (and would have to be redefined after finding a new name for what is currently,
). And yes, commas may indeed be more common in many/most "typical" applications, but we don't know what's more common in the OP's application. Question is whether to bend the tool for the sake of our task or vice-versa… IMO the only reason for preferring&
here is because LaTeX is more suited for it, not anything intrinsic to the syntax.– ShreevatsaR
16 hours ago