usepackage{siunitx} gives errors when used with math code in tabularx












3















I want to use siunitx package for writing the units in my document. However, just adding the line:



usepackage{siunitx}


to the document (and without even using the siunitx commands) gives 84 errors of the type: Missing '}'... Missing '$' ... Extra '}' ... and so on.



Without this line the document compiles and generated fine.



I have managed to locate the source causing the problem, which is the use of math code inside a tabularx.



Here is minimal code to compile:



documentclass[12pt,twoside]{report}
usepackage{siunitx}
usepackage{comment}
usepackage{tabularx}
newcolumntype{Y}{>{centeringarraybackslash}X}
newcolumntype{s}{>{hsize=.25hsizecenteringarraybackslash}X}

begin{document}
begin{center}
begin {table}[h]
caption{Comparison between bla bla bla}
centering
{
renewcommand{arraystretch}{1.5} % renewcommand{arraystretch}{1.5}
begin{tabularx}{0.95linewidth} {Y|s}
hlinehline
column 1 title & column 2 title tabularnewline % [0.5cm]
hline%hline
cell(1,1) & $textrm{w}_0$ tabularnewline
%begin{comment}
cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
cell(4,1) & $0.5textrm{w}_0$ tabularnewline
cell(5,1) & $0.46textrm{w}_0$ tabularnewline

hline
%end{comment}
end{tabularx}
}
label{tab:comparing_table}
end{table}
%
end{center}
end{document}


Now, without the: usepackage{siunitx} the above table compiles just fine.
The problem is with the math code inside the table. The same table with text only also compiles fine.



How can I keep the table with the math in it and with siunitx ???










share|improve this question




















  • 2





    it is presumably a clash with some other package but as you give no indication of your input it is impossible to guess, please try to construct the smallest example that you can that has the error and add to your question.

    – David Carlisle
    Jan 17 at 18:58








  • 2





    It's more likely that you have some syntax error that you typed at the same time you added the package. Find where in your tex file the first error occurs, and the error will likely be nearby.

    – Teepeemm
    Jan 17 at 19:07











  • It is a thesis document, very long and using a lot of packages. How can I pinpoint which one is cuasing the problem ? ?

    – user4861528
    Jan 17 at 19:17






  • 2





    it is much easier for you to do it than anyone else:-) first start with a document that has your thesis preamble but no content other than the table. Check that gives the error. If it does not, then the error is not in the table...., if it does , delete every usepackage line that is loading packages not used in the table, until you get a small example that shows the error. If you delete a package and the error goes, that is the problem...

    – David Carlisle
    Jan 17 at 19:23






  • 1





    Oh I was assuming you had an error in a table from siunitx S columns forget "table" but just have whatever paragraph or equation or whatever is causing the error (the error message log will show the filename and line number of the first error, so basically you just need that line plus whatever else you need to make it a valid latex document.

    – David Carlisle
    Jan 17 at 19:41


















3















I want to use siunitx package for writing the units in my document. However, just adding the line:



usepackage{siunitx}


to the document (and without even using the siunitx commands) gives 84 errors of the type: Missing '}'... Missing '$' ... Extra '}' ... and so on.



Without this line the document compiles and generated fine.



I have managed to locate the source causing the problem, which is the use of math code inside a tabularx.



Here is minimal code to compile:



documentclass[12pt,twoside]{report}
usepackage{siunitx}
usepackage{comment}
usepackage{tabularx}
newcolumntype{Y}{>{centeringarraybackslash}X}
newcolumntype{s}{>{hsize=.25hsizecenteringarraybackslash}X}

begin{document}
begin{center}
begin {table}[h]
caption{Comparison between bla bla bla}
centering
{
renewcommand{arraystretch}{1.5} % renewcommand{arraystretch}{1.5}
begin{tabularx}{0.95linewidth} {Y|s}
hlinehline
column 1 title & column 2 title tabularnewline % [0.5cm]
hline%hline
cell(1,1) & $textrm{w}_0$ tabularnewline
%begin{comment}
cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
cell(4,1) & $0.5textrm{w}_0$ tabularnewline
cell(5,1) & $0.46textrm{w}_0$ tabularnewline

hline
%end{comment}
end{tabularx}
}
label{tab:comparing_table}
end{table}
%
end{center}
end{document}


Now, without the: usepackage{siunitx} the above table compiles just fine.
The problem is with the math code inside the table. The same table with text only also compiles fine.



How can I keep the table with the math in it and with siunitx ???










share|improve this question




















  • 2





    it is presumably a clash with some other package but as you give no indication of your input it is impossible to guess, please try to construct the smallest example that you can that has the error and add to your question.

    – David Carlisle
    Jan 17 at 18:58








  • 2





    It's more likely that you have some syntax error that you typed at the same time you added the package. Find where in your tex file the first error occurs, and the error will likely be nearby.

    – Teepeemm
    Jan 17 at 19:07











  • It is a thesis document, very long and using a lot of packages. How can I pinpoint which one is cuasing the problem ? ?

    – user4861528
    Jan 17 at 19:17






  • 2





    it is much easier for you to do it than anyone else:-) first start with a document that has your thesis preamble but no content other than the table. Check that gives the error. If it does not, then the error is not in the table...., if it does , delete every usepackage line that is loading packages not used in the table, until you get a small example that shows the error. If you delete a package and the error goes, that is the problem...

    – David Carlisle
    Jan 17 at 19:23






  • 1





    Oh I was assuming you had an error in a table from siunitx S columns forget "table" but just have whatever paragraph or equation or whatever is causing the error (the error message log will show the filename and line number of the first error, so basically you just need that line plus whatever else you need to make it a valid latex document.

    – David Carlisle
    Jan 17 at 19:41
















3












3








3








I want to use siunitx package for writing the units in my document. However, just adding the line:



usepackage{siunitx}


to the document (and without even using the siunitx commands) gives 84 errors of the type: Missing '}'... Missing '$' ... Extra '}' ... and so on.



Without this line the document compiles and generated fine.



I have managed to locate the source causing the problem, which is the use of math code inside a tabularx.



Here is minimal code to compile:



documentclass[12pt,twoside]{report}
usepackage{siunitx}
usepackage{comment}
usepackage{tabularx}
newcolumntype{Y}{>{centeringarraybackslash}X}
newcolumntype{s}{>{hsize=.25hsizecenteringarraybackslash}X}

begin{document}
begin{center}
begin {table}[h]
caption{Comparison between bla bla bla}
centering
{
renewcommand{arraystretch}{1.5} % renewcommand{arraystretch}{1.5}
begin{tabularx}{0.95linewidth} {Y|s}
hlinehline
column 1 title & column 2 title tabularnewline % [0.5cm]
hline%hline
cell(1,1) & $textrm{w}_0$ tabularnewline
%begin{comment}
cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
cell(4,1) & $0.5textrm{w}_0$ tabularnewline
cell(5,1) & $0.46textrm{w}_0$ tabularnewline

hline
%end{comment}
end{tabularx}
}
label{tab:comparing_table}
end{table}
%
end{center}
end{document}


Now, without the: usepackage{siunitx} the above table compiles just fine.
The problem is with the math code inside the table. The same table with text only also compiles fine.



How can I keep the table with the math in it and with siunitx ???










share|improve this question
















I want to use siunitx package for writing the units in my document. However, just adding the line:



usepackage{siunitx}


to the document (and without even using the siunitx commands) gives 84 errors of the type: Missing '}'... Missing '$' ... Extra '}' ... and so on.



Without this line the document compiles and generated fine.



I have managed to locate the source causing the problem, which is the use of math code inside a tabularx.



Here is minimal code to compile:



documentclass[12pt,twoside]{report}
usepackage{siunitx}
usepackage{comment}
usepackage{tabularx}
newcolumntype{Y}{>{centeringarraybackslash}X}
newcolumntype{s}{>{hsize=.25hsizecenteringarraybackslash}X}

begin{document}
begin{center}
begin {table}[h]
caption{Comparison between bla bla bla}
centering
{
renewcommand{arraystretch}{1.5} % renewcommand{arraystretch}{1.5}
begin{tabularx}{0.95linewidth} {Y|s}
hlinehline
column 1 title & column 2 title tabularnewline % [0.5cm]
hline%hline
cell(1,1) & $textrm{w}_0$ tabularnewline
%begin{comment}
cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
cell(4,1) & $0.5textrm{w}_0$ tabularnewline
cell(5,1) & $0.46textrm{w}_0$ tabularnewline

hline
%end{comment}
end{tabularx}
}
label{tab:comparing_table}
end{table}
%
end{center}
end{document}


Now, without the: usepackage{siunitx} the above table compiles just fine.
The problem is with the math code inside the table. The same table with text only also compiles fine.



How can I keep the table with the math in it and with siunitx ???







siunitx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 16:10







user4861528

















asked Jan 17 at 18:57









user4861528user4861528

304




304








  • 2





    it is presumably a clash with some other package but as you give no indication of your input it is impossible to guess, please try to construct the smallest example that you can that has the error and add to your question.

    – David Carlisle
    Jan 17 at 18:58








  • 2





    It's more likely that you have some syntax error that you typed at the same time you added the package. Find where in your tex file the first error occurs, and the error will likely be nearby.

    – Teepeemm
    Jan 17 at 19:07











  • It is a thesis document, very long and using a lot of packages. How can I pinpoint which one is cuasing the problem ? ?

    – user4861528
    Jan 17 at 19:17






  • 2





    it is much easier for you to do it than anyone else:-) first start with a document that has your thesis preamble but no content other than the table. Check that gives the error. If it does not, then the error is not in the table...., if it does , delete every usepackage line that is loading packages not used in the table, until you get a small example that shows the error. If you delete a package and the error goes, that is the problem...

    – David Carlisle
    Jan 17 at 19:23






  • 1





    Oh I was assuming you had an error in a table from siunitx S columns forget "table" but just have whatever paragraph or equation or whatever is causing the error (the error message log will show the filename and line number of the first error, so basically you just need that line plus whatever else you need to make it a valid latex document.

    – David Carlisle
    Jan 17 at 19:41
















  • 2





    it is presumably a clash with some other package but as you give no indication of your input it is impossible to guess, please try to construct the smallest example that you can that has the error and add to your question.

    – David Carlisle
    Jan 17 at 18:58








  • 2





    It's more likely that you have some syntax error that you typed at the same time you added the package. Find where in your tex file the first error occurs, and the error will likely be nearby.

    – Teepeemm
    Jan 17 at 19:07











  • It is a thesis document, very long and using a lot of packages. How can I pinpoint which one is cuasing the problem ? ?

    – user4861528
    Jan 17 at 19:17






  • 2





    it is much easier for you to do it than anyone else:-) first start with a document that has your thesis preamble but no content other than the table. Check that gives the error. If it does not, then the error is not in the table...., if it does , delete every usepackage line that is loading packages not used in the table, until you get a small example that shows the error. If you delete a package and the error goes, that is the problem...

    – David Carlisle
    Jan 17 at 19:23






  • 1





    Oh I was assuming you had an error in a table from siunitx S columns forget "table" but just have whatever paragraph or equation or whatever is causing the error (the error message log will show the filename and line number of the first error, so basically you just need that line plus whatever else you need to make it a valid latex document.

    – David Carlisle
    Jan 17 at 19:41










2




2





it is presumably a clash with some other package but as you give no indication of your input it is impossible to guess, please try to construct the smallest example that you can that has the error and add to your question.

– David Carlisle
Jan 17 at 18:58







it is presumably a clash with some other package but as you give no indication of your input it is impossible to guess, please try to construct the smallest example that you can that has the error and add to your question.

– David Carlisle
Jan 17 at 18:58






2




2





It's more likely that you have some syntax error that you typed at the same time you added the package. Find where in your tex file the first error occurs, and the error will likely be nearby.

– Teepeemm
Jan 17 at 19:07





It's more likely that you have some syntax error that you typed at the same time you added the package. Find where in your tex file the first error occurs, and the error will likely be nearby.

– Teepeemm
Jan 17 at 19:07













It is a thesis document, very long and using a lot of packages. How can I pinpoint which one is cuasing the problem ? ?

– user4861528
Jan 17 at 19:17





It is a thesis document, very long and using a lot of packages. How can I pinpoint which one is cuasing the problem ? ?

– user4861528
Jan 17 at 19:17




2




2





it is much easier for you to do it than anyone else:-) first start with a document that has your thesis preamble but no content other than the table. Check that gives the error. If it does not, then the error is not in the table...., if it does , delete every usepackage line that is loading packages not used in the table, until you get a small example that shows the error. If you delete a package and the error goes, that is the problem...

– David Carlisle
Jan 17 at 19:23





it is much easier for you to do it than anyone else:-) first start with a document that has your thesis preamble but no content other than the table. Check that gives the error. If it does not, then the error is not in the table...., if it does , delete every usepackage line that is loading packages not used in the table, until you get a small example that shows the error. If you delete a package and the error goes, that is the problem...

– David Carlisle
Jan 17 at 19:23




1




1





Oh I was assuming you had an error in a table from siunitx S columns forget "table" but just have whatever paragraph or equation or whatever is causing the error (the error message log will show the filename and line number of the first error, so basically you just need that line plus whatever else you need to make it a valid latex document.

– David Carlisle
Jan 17 at 19:41







Oh I was assuming you had an error in a table from siunitx S columns forget "table" but just have whatever paragraph or equation or whatever is causing the error (the error message log will show the filename and line number of the first error, so basically you just need that line plus whatever else you need to make it a valid latex document.

– David Carlisle
Jan 17 at 19:41












2 Answers
2






active

oldest

votes


















2














It seems to me that the problem comes from your custom columntype since using j instead of s works flawless for me.
The s is reserved by the siunitx package.



tabularx



documentclass[12pt,twoside]{report}
usepackage{siunitx}
usepackage{comment}
usepackage{tabularx}
newcolumntype{Y}{>{centeringarraybackslash}X}
newcolumntype{j}{>{hsize=.25hsizecenteringarraybackslash}X}

begin{document}
begin{center}
begin{table}[h]
caption{Comparison between bla bla bla}
centering
{
renewcommand{arraystretch}{1.5} %
begin{tabularx}{0.95linewidth}{Y|j}
hlinehline
column 1 title & column 2 title tabularnewline % [0.5cm]
hline%hline
cell(1,1) & {$textrm{w}_0$} tabularnewline
cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
cell(4,1) & $0.5textrm{w}_0$ tabularnewline
cell(5,1) & $0.46textrm{w}_0$ tabularnewline
hline
end{tabularx}
}
label{tab:comparing_table}
end{table}
end{center}
end{document}





share|improve this answer































    2














    The console output (and the log file) shows



    Package array Warning: Column s is already defined on input line 8.


    When a column type is already defined, array usually warns and overwrites the definition. But Catch 22 is there waiting for us! The s column type is defined by siunitx, so the warning is shown, but siunitx actually does the necessary definition for the column type at begin document! So you end up anyway with the s column type defined by siunitx and this causes the error, because the input in that column is invalid.



    If you aren't sure that overwriting a column type is safe, don't do it.



    There are a few other points to note.




    1. Never place table inside center: this has the only effect of producing unwanted vertical space in the document and the table may or may not be in the middle of that vertical space.


    2. Avoid begin{table}[h] in the hope the float will actually be placed here. It usually won't. LaTeX converts [h] to [ht], but big floats might not find their place in the specified positions and you end up delaying it and all subsequent floats until the end of the current chapter.


    3. Using a group to localize the effect of renewcommand{arraystretch}{1.5} is useless, because the former value will be restored anyway after end{table}.


    4. Put your label next to the caption, which it belongs to.



    5. The correct way to go for using “variable X columns” is to use hsize=<frac>hsize so that the sum of all fractions is the total number of X columns. In your case if the subdivision is 3/4 for the first column and 1/4 for the second column it should be



      >{hsize=1.5hsize}X >{hsize=0.5hsize}X



    Full code, with booktabs features rather than hlinehline and vertical rules.



    documentclass[12pt,twoside]{report}
    usepackage{siunitx}
    usepackage{comment}
    usepackage{tabularx}
    usepackage{booktabs}

    begin{document}

    begin{table}[htp]
    caption{Comparison between bla bla bla}
    label{tab:comparing_table}

    centering
    renewcommand{arraystretch}{1.5}

    begin{tabularx}{0.95linewidth}
    {
    >{centeringhsize=1.5hsize}X
    >{centeringhsize=0.5hsize}X
    }
    toprule
    column 1 title & column 2 title tabularnewline % [0.5cm]
    midrule
    cell(1,1) & $textrm{w}_0$ tabularnewline
    %begin{comment}
    cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
    cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
    cell(4,1) & $0.5textrm{w}_0$ tabularnewline
    cell(5,1) & $0.46textrm{w}_0$ tabularnewline

    bottomrule
    %end{comment}
    end{tabularx}

    end{table}

    end{document}


    enter image description here



    Here is the output with



    >{centering}X c


    for the column specifications:



    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%2f470590%2fusepackagesiunitx-gives-errors-when-used-with-math-code-in-tabularx%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









      2














      It seems to me that the problem comes from your custom columntype since using j instead of s works flawless for me.
      The s is reserved by the siunitx package.



      tabularx



      documentclass[12pt,twoside]{report}
      usepackage{siunitx}
      usepackage{comment}
      usepackage{tabularx}
      newcolumntype{Y}{>{centeringarraybackslash}X}
      newcolumntype{j}{>{hsize=.25hsizecenteringarraybackslash}X}

      begin{document}
      begin{center}
      begin{table}[h]
      caption{Comparison between bla bla bla}
      centering
      {
      renewcommand{arraystretch}{1.5} %
      begin{tabularx}{0.95linewidth}{Y|j}
      hlinehline
      column 1 title & column 2 title tabularnewline % [0.5cm]
      hline%hline
      cell(1,1) & {$textrm{w}_0$} tabularnewline
      cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
      cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
      cell(4,1) & $0.5textrm{w}_0$ tabularnewline
      cell(5,1) & $0.46textrm{w}_0$ tabularnewline
      hline
      end{tabularx}
      }
      label{tab:comparing_table}
      end{table}
      end{center}
      end{document}





      share|improve this answer




























        2














        It seems to me that the problem comes from your custom columntype since using j instead of s works flawless for me.
        The s is reserved by the siunitx package.



        tabularx



        documentclass[12pt,twoside]{report}
        usepackage{siunitx}
        usepackage{comment}
        usepackage{tabularx}
        newcolumntype{Y}{>{centeringarraybackslash}X}
        newcolumntype{j}{>{hsize=.25hsizecenteringarraybackslash}X}

        begin{document}
        begin{center}
        begin{table}[h]
        caption{Comparison between bla bla bla}
        centering
        {
        renewcommand{arraystretch}{1.5} %
        begin{tabularx}{0.95linewidth}{Y|j}
        hlinehline
        column 1 title & column 2 title tabularnewline % [0.5cm]
        hline%hline
        cell(1,1) & {$textrm{w}_0$} tabularnewline
        cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
        cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
        cell(4,1) & $0.5textrm{w}_0$ tabularnewline
        cell(5,1) & $0.46textrm{w}_0$ tabularnewline
        hline
        end{tabularx}
        }
        label{tab:comparing_table}
        end{table}
        end{center}
        end{document}





        share|improve this answer


























          2












          2








          2







          It seems to me that the problem comes from your custom columntype since using j instead of s works flawless for me.
          The s is reserved by the siunitx package.



          tabularx



          documentclass[12pt,twoside]{report}
          usepackage{siunitx}
          usepackage{comment}
          usepackage{tabularx}
          newcolumntype{Y}{>{centeringarraybackslash}X}
          newcolumntype{j}{>{hsize=.25hsizecenteringarraybackslash}X}

          begin{document}
          begin{center}
          begin{table}[h]
          caption{Comparison between bla bla bla}
          centering
          {
          renewcommand{arraystretch}{1.5} %
          begin{tabularx}{0.95linewidth}{Y|j}
          hlinehline
          column 1 title & column 2 title tabularnewline % [0.5cm]
          hline%hline
          cell(1,1) & {$textrm{w}_0$} tabularnewline
          cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
          cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
          cell(4,1) & $0.5textrm{w}_0$ tabularnewline
          cell(5,1) & $0.46textrm{w}_0$ tabularnewline
          hline
          end{tabularx}
          }
          label{tab:comparing_table}
          end{table}
          end{center}
          end{document}





          share|improve this answer













          It seems to me that the problem comes from your custom columntype since using j instead of s works flawless for me.
          The s is reserved by the siunitx package.



          tabularx



          documentclass[12pt,twoside]{report}
          usepackage{siunitx}
          usepackage{comment}
          usepackage{tabularx}
          newcolumntype{Y}{>{centeringarraybackslash}X}
          newcolumntype{j}{>{hsize=.25hsizecenteringarraybackslash}X}

          begin{document}
          begin{center}
          begin{table}[h]
          caption{Comparison between bla bla bla}
          centering
          {
          renewcommand{arraystretch}{1.5} %
          begin{tabularx}{0.95linewidth}{Y|j}
          hlinehline
          column 1 title & column 2 title tabularnewline % [0.5cm]
          hline%hline
          cell(1,1) & {$textrm{w}_0$} tabularnewline
          cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
          cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
          cell(4,1) & $0.5textrm{w}_0$ tabularnewline
          cell(5,1) & $0.46textrm{w}_0$ tabularnewline
          hline
          end{tabularx}
          }
          label{tab:comparing_table}
          end{table}
          end{center}
          end{document}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 20 at 16:19









          G. BayG. Bay

          1,2431826




          1,2431826























              2














              The console output (and the log file) shows



              Package array Warning: Column s is already defined on input line 8.


              When a column type is already defined, array usually warns and overwrites the definition. But Catch 22 is there waiting for us! The s column type is defined by siunitx, so the warning is shown, but siunitx actually does the necessary definition for the column type at begin document! So you end up anyway with the s column type defined by siunitx and this causes the error, because the input in that column is invalid.



              If you aren't sure that overwriting a column type is safe, don't do it.



              There are a few other points to note.




              1. Never place table inside center: this has the only effect of producing unwanted vertical space in the document and the table may or may not be in the middle of that vertical space.


              2. Avoid begin{table}[h] in the hope the float will actually be placed here. It usually won't. LaTeX converts [h] to [ht], but big floats might not find their place in the specified positions and you end up delaying it and all subsequent floats until the end of the current chapter.


              3. Using a group to localize the effect of renewcommand{arraystretch}{1.5} is useless, because the former value will be restored anyway after end{table}.


              4. Put your label next to the caption, which it belongs to.



              5. The correct way to go for using “variable X columns” is to use hsize=<frac>hsize so that the sum of all fractions is the total number of X columns. In your case if the subdivision is 3/4 for the first column and 1/4 for the second column it should be



                >{hsize=1.5hsize}X >{hsize=0.5hsize}X



              Full code, with booktabs features rather than hlinehline and vertical rules.



              documentclass[12pt,twoside]{report}
              usepackage{siunitx}
              usepackage{comment}
              usepackage{tabularx}
              usepackage{booktabs}

              begin{document}

              begin{table}[htp]
              caption{Comparison between bla bla bla}
              label{tab:comparing_table}

              centering
              renewcommand{arraystretch}{1.5}

              begin{tabularx}{0.95linewidth}
              {
              >{centeringhsize=1.5hsize}X
              >{centeringhsize=0.5hsize}X
              }
              toprule
              column 1 title & column 2 title tabularnewline % [0.5cm]
              midrule
              cell(1,1) & $textrm{w}_0$ tabularnewline
              %begin{comment}
              cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
              cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
              cell(4,1) & $0.5textrm{w}_0$ tabularnewline
              cell(5,1) & $0.46textrm{w}_0$ tabularnewline

              bottomrule
              %end{comment}
              end{tabularx}

              end{table}

              end{document}


              enter image description here



              Here is the output with



              >{centering}X c


              for the column specifications:



              enter image description here






              share|improve this answer




























                2














                The console output (and the log file) shows



                Package array Warning: Column s is already defined on input line 8.


                When a column type is already defined, array usually warns and overwrites the definition. But Catch 22 is there waiting for us! The s column type is defined by siunitx, so the warning is shown, but siunitx actually does the necessary definition for the column type at begin document! So you end up anyway with the s column type defined by siunitx and this causes the error, because the input in that column is invalid.



                If you aren't sure that overwriting a column type is safe, don't do it.



                There are a few other points to note.




                1. Never place table inside center: this has the only effect of producing unwanted vertical space in the document and the table may or may not be in the middle of that vertical space.


                2. Avoid begin{table}[h] in the hope the float will actually be placed here. It usually won't. LaTeX converts [h] to [ht], but big floats might not find their place in the specified positions and you end up delaying it and all subsequent floats until the end of the current chapter.


                3. Using a group to localize the effect of renewcommand{arraystretch}{1.5} is useless, because the former value will be restored anyway after end{table}.


                4. Put your label next to the caption, which it belongs to.



                5. The correct way to go for using “variable X columns” is to use hsize=<frac>hsize so that the sum of all fractions is the total number of X columns. In your case if the subdivision is 3/4 for the first column and 1/4 for the second column it should be



                  >{hsize=1.5hsize}X >{hsize=0.5hsize}X



                Full code, with booktabs features rather than hlinehline and vertical rules.



                documentclass[12pt,twoside]{report}
                usepackage{siunitx}
                usepackage{comment}
                usepackage{tabularx}
                usepackage{booktabs}

                begin{document}

                begin{table}[htp]
                caption{Comparison between bla bla bla}
                label{tab:comparing_table}

                centering
                renewcommand{arraystretch}{1.5}

                begin{tabularx}{0.95linewidth}
                {
                >{centeringhsize=1.5hsize}X
                >{centeringhsize=0.5hsize}X
                }
                toprule
                column 1 title & column 2 title tabularnewline % [0.5cm]
                midrule
                cell(1,1) & $textrm{w}_0$ tabularnewline
                %begin{comment}
                cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
                cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
                cell(4,1) & $0.5textrm{w}_0$ tabularnewline
                cell(5,1) & $0.46textrm{w}_0$ tabularnewline

                bottomrule
                %end{comment}
                end{tabularx}

                end{table}

                end{document}


                enter image description here



                Here is the output with



                >{centering}X c


                for the column specifications:



                enter image description here






                share|improve this answer


























                  2












                  2








                  2







                  The console output (and the log file) shows



                  Package array Warning: Column s is already defined on input line 8.


                  When a column type is already defined, array usually warns and overwrites the definition. But Catch 22 is there waiting for us! The s column type is defined by siunitx, so the warning is shown, but siunitx actually does the necessary definition for the column type at begin document! So you end up anyway with the s column type defined by siunitx and this causes the error, because the input in that column is invalid.



                  If you aren't sure that overwriting a column type is safe, don't do it.



                  There are a few other points to note.




                  1. Never place table inside center: this has the only effect of producing unwanted vertical space in the document and the table may or may not be in the middle of that vertical space.


                  2. Avoid begin{table}[h] in the hope the float will actually be placed here. It usually won't. LaTeX converts [h] to [ht], but big floats might not find their place in the specified positions and you end up delaying it and all subsequent floats until the end of the current chapter.


                  3. Using a group to localize the effect of renewcommand{arraystretch}{1.5} is useless, because the former value will be restored anyway after end{table}.


                  4. Put your label next to the caption, which it belongs to.



                  5. The correct way to go for using “variable X columns” is to use hsize=<frac>hsize so that the sum of all fractions is the total number of X columns. In your case if the subdivision is 3/4 for the first column and 1/4 for the second column it should be



                    >{hsize=1.5hsize}X >{hsize=0.5hsize}X



                  Full code, with booktabs features rather than hlinehline and vertical rules.



                  documentclass[12pt,twoside]{report}
                  usepackage{siunitx}
                  usepackage{comment}
                  usepackage{tabularx}
                  usepackage{booktabs}

                  begin{document}

                  begin{table}[htp]
                  caption{Comparison between bla bla bla}
                  label{tab:comparing_table}

                  centering
                  renewcommand{arraystretch}{1.5}

                  begin{tabularx}{0.95linewidth}
                  {
                  >{centeringhsize=1.5hsize}X
                  >{centeringhsize=0.5hsize}X
                  }
                  toprule
                  column 1 title & column 2 title tabularnewline % [0.5cm]
                  midrule
                  cell(1,1) & $textrm{w}_0$ tabularnewline
                  %begin{comment}
                  cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
                  cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
                  cell(4,1) & $0.5textrm{w}_0$ tabularnewline
                  cell(5,1) & $0.46textrm{w}_0$ tabularnewline

                  bottomrule
                  %end{comment}
                  end{tabularx}

                  end{table}

                  end{document}


                  enter image description here



                  Here is the output with



                  >{centering}X c


                  for the column specifications:



                  enter image description here






                  share|improve this answer













                  The console output (and the log file) shows



                  Package array Warning: Column s is already defined on input line 8.


                  When a column type is already defined, array usually warns and overwrites the definition. But Catch 22 is there waiting for us! The s column type is defined by siunitx, so the warning is shown, but siunitx actually does the necessary definition for the column type at begin document! So you end up anyway with the s column type defined by siunitx and this causes the error, because the input in that column is invalid.



                  If you aren't sure that overwriting a column type is safe, don't do it.



                  There are a few other points to note.




                  1. Never place table inside center: this has the only effect of producing unwanted vertical space in the document and the table may or may not be in the middle of that vertical space.


                  2. Avoid begin{table}[h] in the hope the float will actually be placed here. It usually won't. LaTeX converts [h] to [ht], but big floats might not find their place in the specified positions and you end up delaying it and all subsequent floats until the end of the current chapter.


                  3. Using a group to localize the effect of renewcommand{arraystretch}{1.5} is useless, because the former value will be restored anyway after end{table}.


                  4. Put your label next to the caption, which it belongs to.



                  5. The correct way to go for using “variable X columns” is to use hsize=<frac>hsize so that the sum of all fractions is the total number of X columns. In your case if the subdivision is 3/4 for the first column and 1/4 for the second column it should be



                    >{hsize=1.5hsize}X >{hsize=0.5hsize}X



                  Full code, with booktabs features rather than hlinehline and vertical rules.



                  documentclass[12pt,twoside]{report}
                  usepackage{siunitx}
                  usepackage{comment}
                  usepackage{tabularx}
                  usepackage{booktabs}

                  begin{document}

                  begin{table}[htp]
                  caption{Comparison between bla bla bla}
                  label{tab:comparing_table}

                  centering
                  renewcommand{arraystretch}{1.5}

                  begin{tabularx}{0.95linewidth}
                  {
                  >{centeringhsize=1.5hsize}X
                  >{centeringhsize=0.5hsize}X
                  }
                  toprule
                  column 1 title & column 2 title tabularnewline % [0.5cm]
                  midrule
                  cell(1,1) & $textrm{w}_0$ tabularnewline
                  %begin{comment}
                  cell(2,1) & $frac{textrm{w}_0}{sqrt{2}}approx 0.7textrm{w}_0$ tabularnewline
                  cell(3,1) & $frac{textrm{w}_0}{sqrt{3}}approx 0.58textrm{w}_0$ tabularnewline
                  cell(4,1) & $0.5textrm{w}_0$ tabularnewline
                  cell(5,1) & $0.46textrm{w}_0$ tabularnewline

                  bottomrule
                  %end{comment}
                  end{tabularx}

                  end{table}

                  end{document}


                  enter image description here



                  Here is the output with



                  >{centering}X c


                  for the column specifications:



                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 20 at 17:04









                  egregegreg

                  715k8618983185




                  715k8618983185






























                      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%2f470590%2fusepackagesiunitx-gives-errors-when-used-with-math-code-in-tabularx%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

                      How to change which sound is reproduced for terminal bell?

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?

                      Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents