csvsimple vs. conditional row coloring












4














I've a CSV file what I want process with csvsimple. My desire is to color some rows based on a conditional (one specified column has bigger value). Here is an MWE:



documentclass[12pt]{article}
usepackage{filecontents}
usepackage{csvsimple}
usepackage[table]{xcolor}
begin{document}
begin{filecontents*}{mwe.csv}
a,b,c,d
1,1,2,2
1,3,2,1
end{filecontents*}
begin{tabular}{*{4}{c}}
csvreader[
head to column names,
before line={ifnumd>1rowcolor{gray}fi},
late after line={\}
]{mwe.csv}{}{
a&b&c&d
}
end{tabular}
end{document}


In this case I gave an error message:



! Misplaced noalign.  
<recently read> noalign
l.18 }


How can I solve it?










share|improve this question



























    4














    I've a CSV file what I want process with csvsimple. My desire is to color some rows based on a conditional (one specified column has bigger value). Here is an MWE:



    documentclass[12pt]{article}
    usepackage{filecontents}
    usepackage{csvsimple}
    usepackage[table]{xcolor}
    begin{document}
    begin{filecontents*}{mwe.csv}
    a,b,c,d
    1,1,2,2
    1,3,2,1
    end{filecontents*}
    begin{tabular}{*{4}{c}}
    csvreader[
    head to column names,
    before line={ifnumd>1rowcolor{gray}fi},
    late after line={\}
    ]{mwe.csv}{}{
    a&b&c&d
    }
    end{tabular}
    end{document}


    In this case I gave an error message:



    ! Misplaced noalign.  
    <recently read> noalign
    l.18 }


    How can I solve it?










    share|improve this question

























      4












      4








      4


      0





      I've a CSV file what I want process with csvsimple. My desire is to color some rows based on a conditional (one specified column has bigger value). Here is an MWE:



      documentclass[12pt]{article}
      usepackage{filecontents}
      usepackage{csvsimple}
      usepackage[table]{xcolor}
      begin{document}
      begin{filecontents*}{mwe.csv}
      a,b,c,d
      1,1,2,2
      1,3,2,1
      end{filecontents*}
      begin{tabular}{*{4}{c}}
      csvreader[
      head to column names,
      before line={ifnumd>1rowcolor{gray}fi},
      late after line={\}
      ]{mwe.csv}{}{
      a&b&c&d
      }
      end{tabular}
      end{document}


      In this case I gave an error message:



      ! Misplaced noalign.  
      <recently read> noalign
      l.18 }


      How can I solve it?










      share|improve this question













      I've a CSV file what I want process with csvsimple. My desire is to color some rows based on a conditional (one specified column has bigger value). Here is an MWE:



      documentclass[12pt]{article}
      usepackage{filecontents}
      usepackage{csvsimple}
      usepackage[table]{xcolor}
      begin{document}
      begin{filecontents*}{mwe.csv}
      a,b,c,d
      1,1,2,2
      1,3,2,1
      end{filecontents*}
      begin{tabular}{*{4}{c}}
      csvreader[
      head to column names,
      before line={ifnumd>1rowcolor{gray}fi},
      late after line={\}
      ]{mwe.csv}{}{
      a&b&c&d
      }
      end{tabular}
      end{document}


      In this case I gave an error message:



      ! Misplaced noalign.  
      <recently read> noalign
      l.18 }


      How can I solve it?







      conditionals csv csvsimple rowcolor






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      uzsolt

      911714




      911714






















          2 Answers
          2






          active

          oldest

          votes


















          6














          Your error stems from rowcolornot being at the very beginning of the row. You can fix that by adding an additional \ at the beginning of a row. It would also be better to use a filter (section 3.4 of the manual) to process conditionals:



          documentclass[12pt]{article}
          usepackage{csvsimple}
          usepackage[table]{xcolor}

          usepackage{filecontents}
          begin{filecontents*}{jobname.csv}
          a,b,c,d
          1,1,2,2
          1,3,2,1
          3,4,5,0
          6,7,8,1
          8,6,4,2
          9,1,2,4
          0,0,1,1
          end{filecontents*}


          begin{document}
          begin{tabular}{*{4}{c}}
          csvreader[head to column names,
          full filter=ifnumgreater{d}{1}
          {\rowcolor{gray} csvfilteraccept}
          {\ csvfilteraccept}
          ]{jobname.csv}{}{csvlinetotablerow}%
          end{tabular}
          end{document}


          enter image description here






          share|improve this answer























          • It doesn't work well if you've a third line in CSV ("1,1,2,2") or the second line matches too.
            – uzsolt
            2 days ago








          • 1




            @uzsolt fixed it
            – DG'
            2 days ago










          • Thank you, it works well!
            – uzsolt
            2 days ago



















          1














          Try this solution. It adds a line break after each row.



           
          documentclass[12pt]{article}
          usepackage{filecontents}
          usepackage{csvsimple}
          usepackage[table]{xcolor}
          begin{document}
          begin{filecontents*}{mwe.csv}
          a,b,c,d
          1,1,2,2
          5,3,9,1
          7,8,2,9
          5,3,9,1
          5,3,9,1
          7,8,2,9
          end{filecontents*}

          csvreader[tabular=cccc,
          head to column names,
          before line={ifnumd>1\rowcolor{gray}else\fi}
          ]{mwe.csv}{}{
          a&b&c&d
          }


          end{document}



          enter image description here



          If you don't else\ then you will have this result:



          enter image description here






          share|improve this answer










          New contributor




          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • There are empty lines. Compare it without the before line={ifnumd>1\rowcolor{gray}else\fi} option!
            – uzsolt
            2 days ago












          • I want equal height :)
            – uzsolt
            2 days ago










          • @Compiii Your solution works great, if you omit the option tabular=cccc, (it adds an additional line break at the end) and put the whole csvreader-statement inside of the tabular-environment.
            – DG'
            2 days ago













          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%2f468208%2fcsvsimple-vs-conditional-row-coloring%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









          6














          Your error stems from rowcolornot being at the very beginning of the row. You can fix that by adding an additional \ at the beginning of a row. It would also be better to use a filter (section 3.4 of the manual) to process conditionals:



          documentclass[12pt]{article}
          usepackage{csvsimple}
          usepackage[table]{xcolor}

          usepackage{filecontents}
          begin{filecontents*}{jobname.csv}
          a,b,c,d
          1,1,2,2
          1,3,2,1
          3,4,5,0
          6,7,8,1
          8,6,4,2
          9,1,2,4
          0,0,1,1
          end{filecontents*}


          begin{document}
          begin{tabular}{*{4}{c}}
          csvreader[head to column names,
          full filter=ifnumgreater{d}{1}
          {\rowcolor{gray} csvfilteraccept}
          {\ csvfilteraccept}
          ]{jobname.csv}{}{csvlinetotablerow}%
          end{tabular}
          end{document}


          enter image description here






          share|improve this answer























          • It doesn't work well if you've a third line in CSV ("1,1,2,2") or the second line matches too.
            – uzsolt
            2 days ago








          • 1




            @uzsolt fixed it
            – DG'
            2 days ago










          • Thank you, it works well!
            – uzsolt
            2 days ago
















          6














          Your error stems from rowcolornot being at the very beginning of the row. You can fix that by adding an additional \ at the beginning of a row. It would also be better to use a filter (section 3.4 of the manual) to process conditionals:



          documentclass[12pt]{article}
          usepackage{csvsimple}
          usepackage[table]{xcolor}

          usepackage{filecontents}
          begin{filecontents*}{jobname.csv}
          a,b,c,d
          1,1,2,2
          1,3,2,1
          3,4,5,0
          6,7,8,1
          8,6,4,2
          9,1,2,4
          0,0,1,1
          end{filecontents*}


          begin{document}
          begin{tabular}{*{4}{c}}
          csvreader[head to column names,
          full filter=ifnumgreater{d}{1}
          {\rowcolor{gray} csvfilteraccept}
          {\ csvfilteraccept}
          ]{jobname.csv}{}{csvlinetotablerow}%
          end{tabular}
          end{document}


          enter image description here






          share|improve this answer























          • It doesn't work well if you've a third line in CSV ("1,1,2,2") or the second line matches too.
            – uzsolt
            2 days ago








          • 1




            @uzsolt fixed it
            – DG'
            2 days ago










          • Thank you, it works well!
            – uzsolt
            2 days ago














          6












          6








          6






          Your error stems from rowcolornot being at the very beginning of the row. You can fix that by adding an additional \ at the beginning of a row. It would also be better to use a filter (section 3.4 of the manual) to process conditionals:



          documentclass[12pt]{article}
          usepackage{csvsimple}
          usepackage[table]{xcolor}

          usepackage{filecontents}
          begin{filecontents*}{jobname.csv}
          a,b,c,d
          1,1,2,2
          1,3,2,1
          3,4,5,0
          6,7,8,1
          8,6,4,2
          9,1,2,4
          0,0,1,1
          end{filecontents*}


          begin{document}
          begin{tabular}{*{4}{c}}
          csvreader[head to column names,
          full filter=ifnumgreater{d}{1}
          {\rowcolor{gray} csvfilteraccept}
          {\ csvfilteraccept}
          ]{jobname.csv}{}{csvlinetotablerow}%
          end{tabular}
          end{document}


          enter image description here






          share|improve this answer














          Your error stems from rowcolornot being at the very beginning of the row. You can fix that by adding an additional \ at the beginning of a row. It would also be better to use a filter (section 3.4 of the manual) to process conditionals:



          documentclass[12pt]{article}
          usepackage{csvsimple}
          usepackage[table]{xcolor}

          usepackage{filecontents}
          begin{filecontents*}{jobname.csv}
          a,b,c,d
          1,1,2,2
          1,3,2,1
          3,4,5,0
          6,7,8,1
          8,6,4,2
          9,1,2,4
          0,0,1,1
          end{filecontents*}


          begin{document}
          begin{tabular}{*{4}{c}}
          csvreader[head to column names,
          full filter=ifnumgreater{d}{1}
          {\rowcolor{gray} csvfilteraccept}
          {\ csvfilteraccept}
          ]{jobname.csv}{}{csvlinetotablerow}%
          end{tabular}
          end{document}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          DG'

          9,30511741




          9,30511741












          • It doesn't work well if you've a third line in CSV ("1,1,2,2") or the second line matches too.
            – uzsolt
            2 days ago








          • 1




            @uzsolt fixed it
            – DG'
            2 days ago










          • Thank you, it works well!
            – uzsolt
            2 days ago


















          • It doesn't work well if you've a third line in CSV ("1,1,2,2") or the second line matches too.
            – uzsolt
            2 days ago








          • 1




            @uzsolt fixed it
            – DG'
            2 days ago










          • Thank you, it works well!
            – uzsolt
            2 days ago
















          It doesn't work well if you've a third line in CSV ("1,1,2,2") or the second line matches too.
          – uzsolt
          2 days ago






          It doesn't work well if you've a third line in CSV ("1,1,2,2") or the second line matches too.
          – uzsolt
          2 days ago






          1




          1




          @uzsolt fixed it
          – DG'
          2 days ago




          @uzsolt fixed it
          – DG'
          2 days ago












          Thank you, it works well!
          – uzsolt
          2 days ago




          Thank you, it works well!
          – uzsolt
          2 days ago











          1














          Try this solution. It adds a line break after each row.



           
          documentclass[12pt]{article}
          usepackage{filecontents}
          usepackage{csvsimple}
          usepackage[table]{xcolor}
          begin{document}
          begin{filecontents*}{mwe.csv}
          a,b,c,d
          1,1,2,2
          5,3,9,1
          7,8,2,9
          5,3,9,1
          5,3,9,1
          7,8,2,9
          end{filecontents*}

          csvreader[tabular=cccc,
          head to column names,
          before line={ifnumd>1\rowcolor{gray}else\fi}
          ]{mwe.csv}{}{
          a&b&c&d
          }


          end{document}



          enter image description here



          If you don't else\ then you will have this result:



          enter image description here






          share|improve this answer










          New contributor




          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • There are empty lines. Compare it without the before line={ifnumd>1\rowcolor{gray}else\fi} option!
            – uzsolt
            2 days ago












          • I want equal height :)
            – uzsolt
            2 days ago










          • @Compiii Your solution works great, if you omit the option tabular=cccc, (it adds an additional line break at the end) and put the whole csvreader-statement inside of the tabular-environment.
            – DG'
            2 days ago


















          1














          Try this solution. It adds a line break after each row.



           
          documentclass[12pt]{article}
          usepackage{filecontents}
          usepackage{csvsimple}
          usepackage[table]{xcolor}
          begin{document}
          begin{filecontents*}{mwe.csv}
          a,b,c,d
          1,1,2,2
          5,3,9,1
          7,8,2,9
          5,3,9,1
          5,3,9,1
          7,8,2,9
          end{filecontents*}

          csvreader[tabular=cccc,
          head to column names,
          before line={ifnumd>1\rowcolor{gray}else\fi}
          ]{mwe.csv}{}{
          a&b&c&d
          }


          end{document}



          enter image description here



          If you don't else\ then you will have this result:



          enter image description here






          share|improve this answer










          New contributor




          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • There are empty lines. Compare it without the before line={ifnumd>1\rowcolor{gray}else\fi} option!
            – uzsolt
            2 days ago












          • I want equal height :)
            – uzsolt
            2 days ago










          • @Compiii Your solution works great, if you omit the option tabular=cccc, (it adds an additional line break at the end) and put the whole csvreader-statement inside of the tabular-environment.
            – DG'
            2 days ago
















          1












          1








          1






          Try this solution. It adds a line break after each row.



           
          documentclass[12pt]{article}
          usepackage{filecontents}
          usepackage{csvsimple}
          usepackage[table]{xcolor}
          begin{document}
          begin{filecontents*}{mwe.csv}
          a,b,c,d
          1,1,2,2
          5,3,9,1
          7,8,2,9
          5,3,9,1
          5,3,9,1
          7,8,2,9
          end{filecontents*}

          csvreader[tabular=cccc,
          head to column names,
          before line={ifnumd>1\rowcolor{gray}else\fi}
          ]{mwe.csv}{}{
          a&b&c&d
          }


          end{document}



          enter image description here



          If you don't else\ then you will have this result:



          enter image description here






          share|improve this answer










          New contributor




          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          Try this solution. It adds a line break after each row.



           
          documentclass[12pt]{article}
          usepackage{filecontents}
          usepackage{csvsimple}
          usepackage[table]{xcolor}
          begin{document}
          begin{filecontents*}{mwe.csv}
          a,b,c,d
          1,1,2,2
          5,3,9,1
          7,8,2,9
          5,3,9,1
          5,3,9,1
          7,8,2,9
          end{filecontents*}

          csvreader[tabular=cccc,
          head to column names,
          before line={ifnumd>1\rowcolor{gray}else\fi}
          ]{mwe.csv}{}{
          a&b&c&d
          }


          end{document}



          enter image description here



          If you don't else\ then you will have this result:



          enter image description here







          share|improve this answer










          New contributor




          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer








          edited 2 days ago





















          New contributor




          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 2 days ago









          Compiii

          112




          112




          New contributor




          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Compiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • There are empty lines. Compare it without the before line={ifnumd>1\rowcolor{gray}else\fi} option!
            – uzsolt
            2 days ago












          • I want equal height :)
            – uzsolt
            2 days ago










          • @Compiii Your solution works great, if you omit the option tabular=cccc, (it adds an additional line break at the end) and put the whole csvreader-statement inside of the tabular-environment.
            – DG'
            2 days ago




















          • There are empty lines. Compare it without the before line={ifnumd>1\rowcolor{gray}else\fi} option!
            – uzsolt
            2 days ago












          • I want equal height :)
            – uzsolt
            2 days ago










          • @Compiii Your solution works great, if you omit the option tabular=cccc, (it adds an additional line break at the end) and put the whole csvreader-statement inside of the tabular-environment.
            – DG'
            2 days ago


















          There are empty lines. Compare it without the before line={ifnumd>1\rowcolor{gray}else\fi} option!
          – uzsolt
          2 days ago






          There are empty lines. Compare it without the before line={ifnumd>1\rowcolor{gray}else\fi} option!
          – uzsolt
          2 days ago














          I want equal height :)
          – uzsolt
          2 days ago




          I want equal height :)
          – uzsolt
          2 days ago












          @Compiii Your solution works great, if you omit the option tabular=cccc, (it adds an additional line break at the end) and put the whole csvreader-statement inside of the tabular-environment.
          – DG'
          2 days ago






          @Compiii Your solution works great, if you omit the option tabular=cccc, (it adds an additional line break at the end) and put the whole csvreader-statement inside of the tabular-environment.
          – DG'
          2 days ago




















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f468208%2fcsvsimple-vs-conditional-row-coloring%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

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy