Misplaced noalign when centering tabularx cell
I have a minimal LaTeX document like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centering A & B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

I would like to center the table headers but left-align the columns. However, when I add centering to the B header, like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centering A & centering B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
I get this error:
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
horizontal-alignment tabularx
add a comment |
I have a minimal LaTeX document like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centering A & B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

I would like to center the table headers but left-align the columns. However, when I add centering to the B header, like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centering A & centering B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
I get this error:
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
horizontal-alignment tabularx
Related/duplicate: Centering intabularxandXcolumns
– Werner
2 hours ago
add a comment |
I have a minimal LaTeX document like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centering A & B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

I would like to center the table headers but left-align the columns. However, when I add centering to the B header, like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centering A & centering B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
I get this error:
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
horizontal-alignment tabularx
I have a minimal LaTeX document like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centering A & B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

I would like to center the table headers but left-align the columns. However, when I add centering to the B header, like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centering A & centering B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
I get this error:
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
! Misplaced noalign.
hline ->noalign
{ifnum 0=`}fi hrule @height arrayrulewidth futurelet...
l.8 end{tabularx}
! Extra alignment tab has been changed to cr.
<recently read> endtemplate
l.8 end{tabularx}
horizontal-alignment tabularx
horizontal-alignment tabularx
asked 3 hours ago
Nathaniel M. BeaverNathaniel M. Beaver
23817
23817
Related/duplicate: Centering intabularxandXcolumns
– Werner
2 hours ago
add a comment |
Related/duplicate: Centering intabularxandXcolumns
– Werner
2 hours ago
Related/duplicate: Centering in
tabularx and X columns– Werner
2 hours ago
Related/duplicate: Centering in
tabularx and X columns– Werner
2 hours ago
add a comment |
2 Answers
2
active
oldest
votes
Page 2 of the tabularx documentation says that you have to use arraybackslash after centering (or raggedright or ragggedleft). Use like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centeringarraybackslash A & centeringarraybackslash B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
LaTeX's text alignment commands redefine \ so that they don't mean “a new line in the table” anymore. The arraybackslash command does let\tabularnewline so that it will work again.
add a comment |
You can simply use a multicolumn{1}{c}{...} for the column heads. Or load makecell and use its thead command (by default, its content is centred, both horizontally and vertically), which has the possibility to define a common formatting of all theads arguments. Here is an example of both methods:
documentclass{article}
usepackage{tabularx, makecell, xcolor}
renewcommand{theadfont}{normalsizebfseriescolor{red}}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
multicolumn{1}{c}{A} & multicolumn{1}{c}{B} \ hline
1.0 & 2.0 \
end{tabularx}
vspace{4ex}
noindent
begin{tabularx}{linewidth}{ X | X }
thead{A} & thead{B} \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

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%2f475871%2fmisplaced-noalign-when-centering-tabularx-cell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Page 2 of the tabularx documentation says that you have to use arraybackslash after centering (or raggedright or ragggedleft). Use like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centeringarraybackslash A & centeringarraybackslash B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
LaTeX's text alignment commands redefine \ so that they don't mean “a new line in the table” anymore. The arraybackslash command does let\tabularnewline so that it will work again.
add a comment |
Page 2 of the tabularx documentation says that you have to use arraybackslash after centering (or raggedright or ragggedleft). Use like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centeringarraybackslash A & centeringarraybackslash B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
LaTeX's text alignment commands redefine \ so that they don't mean “a new line in the table” anymore. The arraybackslash command does let\tabularnewline so that it will work again.
add a comment |
Page 2 of the tabularx documentation says that you have to use arraybackslash after centering (or raggedright or ragggedleft). Use like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centeringarraybackslash A & centeringarraybackslash B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
LaTeX's text alignment commands redefine \ so that they don't mean “a new line in the table” anymore. The arraybackslash command does let\tabularnewline so that it will work again.
Page 2 of the tabularx documentation says that you have to use arraybackslash after centering (or raggedright or ragggedleft). Use like this:
documentclass{article}
usepackage{tabularx}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
centeringarraybackslash A & centeringarraybackslash B \ hline
1.0 & 2.0 \
end{tabularx}
end{document}
LaTeX's text alignment commands redefine \ so that they don't mean “a new line in the table” anymore. The arraybackslash command does let\tabularnewline so that it will work again.
answered 3 hours ago
Phelype OleinikPhelype Oleinik
23.5k54586
23.5k54586
add a comment |
add a comment |
You can simply use a multicolumn{1}{c}{...} for the column heads. Or load makecell and use its thead command (by default, its content is centred, both horizontally and vertically), which has the possibility to define a common formatting of all theads arguments. Here is an example of both methods:
documentclass{article}
usepackage{tabularx, makecell, xcolor}
renewcommand{theadfont}{normalsizebfseriescolor{red}}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
multicolumn{1}{c}{A} & multicolumn{1}{c}{B} \ hline
1.0 & 2.0 \
end{tabularx}
vspace{4ex}
noindent
begin{tabularx}{linewidth}{ X | X }
thead{A} & thead{B} \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

add a comment |
You can simply use a multicolumn{1}{c}{...} for the column heads. Or load makecell and use its thead command (by default, its content is centred, both horizontally and vertically), which has the possibility to define a common formatting of all theads arguments. Here is an example of both methods:
documentclass{article}
usepackage{tabularx, makecell, xcolor}
renewcommand{theadfont}{normalsizebfseriescolor{red}}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
multicolumn{1}{c}{A} & multicolumn{1}{c}{B} \ hline
1.0 & 2.0 \
end{tabularx}
vspace{4ex}
noindent
begin{tabularx}{linewidth}{ X | X }
thead{A} & thead{B} \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

add a comment |
You can simply use a multicolumn{1}{c}{...} for the column heads. Or load makecell and use its thead command (by default, its content is centred, both horizontally and vertically), which has the possibility to define a common formatting of all theads arguments. Here is an example of both methods:
documentclass{article}
usepackage{tabularx, makecell, xcolor}
renewcommand{theadfont}{normalsizebfseriescolor{red}}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
multicolumn{1}{c}{A} & multicolumn{1}{c}{B} \ hline
1.0 & 2.0 \
end{tabularx}
vspace{4ex}
noindent
begin{tabularx}{linewidth}{ X | X }
thead{A} & thead{B} \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

You can simply use a multicolumn{1}{c}{...} for the column heads. Or load makecell and use its thead command (by default, its content is centred, both horizontally and vertically), which has the possibility to define a common formatting of all theads arguments. Here is an example of both methods:
documentclass{article}
usepackage{tabularx, makecell, xcolor}
renewcommand{theadfont}{normalsizebfseriescolor{red}}
begin{document}
noindent
begin{tabularx}{linewidth}{ X | X }
multicolumn{1}{c}{A} & multicolumn{1}{c}{B} \ hline
1.0 & 2.0 \
end{tabularx}
vspace{4ex}
noindent
begin{tabularx}{linewidth}{ X | X }
thead{A} & thead{B} \ hline
1.0 & 2.0 \
end{tabularx}
end{document}

edited 2 hours ago
answered 2 hours ago
BernardBernard
170k774201
170k774201
add a comment |
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%2f475871%2fmisplaced-noalign-when-centering-tabularx-cell%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
Related/duplicate: Centering in
tabularxandXcolumns– Werner
2 hours ago