Misplaced noalign when centering tabularx cell












1















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}


A B 1.0 2.0



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}









share|improve this question























  • Related/duplicate: Centering in tabularx and X columns

    – Werner
    2 hours ago
















1















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}


A B 1.0 2.0



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}









share|improve this question























  • Related/duplicate: Centering in tabularx and X columns

    – Werner
    2 hours ago














1












1








1








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}


A B 1.0 2.0



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}









share|improve this question














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}


A B 1.0 2.0



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









Nathaniel M. BeaverNathaniel M. Beaver

23817




23817













  • Related/duplicate: Centering in tabularx and X columns

    – 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





Related/duplicate: Centering in tabularx and X columns

– Werner
2 hours ago










2 Answers
2






active

oldest

votes


















3














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.






share|improve this answer































    2














    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}


    enter image description here






    share|improve this answer

























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      3














      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.






      share|improve this answer




























        3














        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.






        share|improve this answer


























          3












          3








          3







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Phelype OleinikPhelype Oleinik

          23.5k54586




          23.5k54586























              2














              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}


              enter image description here






              share|improve this answer






























                2














                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}


                enter image description here






                share|improve this answer




























                  2












                  2








                  2







                  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}


                  enter image description here






                  share|improve this answer















                  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}


                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 2 hours ago

























                  answered 2 hours ago









                  BernardBernard

                  170k774201




                  170k774201






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Котор

                      Потомский, Вадим Владимирович

                      Бедствия войны