How to change only the color of numbers (and not units) with numprint?












5














This question is related to this one: Colour only the text in a tabularx environment



I want to write as a succession of equality in blue (only the numbers) so that each line of the table has a corresponding equality line to its right.



capture



documentclass{article}
usepackage{amsmath,numprint,tabularx,xcolor}

begin{document}
begin{minipage}{.4linewidth}
begin{tabularx}{5cm}{|*{11}{>{leavevmodecolor{blue}}X|}}
hline
multicolumn{2}{|c|}{$rm m^2$} &
multicolumn{2}{c|}{$rm dm^2$} &
multicolumn{2}{c|}{$rm cm^2$} &
multicolumn{2}{c|}{$rm mm^2$} \
hline
&&&4,&&&& \
&&&4&0&0&0& 0,\
&0,&0&4&&&& \
hline
end{tabularx}
end{minipage}quad
begin{minipage}{.2linewidth}
begin{align*}
&numprint[dm^2]{4}\
&=numprint[mm^2]{40000}\
&=numprint[m^2]{0,04}
end{align*}
end{minipage}

end{document}


In the numprint manual, there is a hack that allows you to color the negative numbers on pages 18-19, I couldn't modify it to write the numbers in blue.



makeatletter
expandafterrenewcommandcsname nprt@sign@-endcsname{%
color{red}{ensuremath{-}}}
makeatother









share|improve this question



























    5














    This question is related to this one: Colour only the text in a tabularx environment



    I want to write as a succession of equality in blue (only the numbers) so that each line of the table has a corresponding equality line to its right.



    capture



    documentclass{article}
    usepackage{amsmath,numprint,tabularx,xcolor}

    begin{document}
    begin{minipage}{.4linewidth}
    begin{tabularx}{5cm}{|*{11}{>{leavevmodecolor{blue}}X|}}
    hline
    multicolumn{2}{|c|}{$rm m^2$} &
    multicolumn{2}{c|}{$rm dm^2$} &
    multicolumn{2}{c|}{$rm cm^2$} &
    multicolumn{2}{c|}{$rm mm^2$} \
    hline
    &&&4,&&&& \
    &&&4&0&0&0& 0,\
    &0,&0&4&&&& \
    hline
    end{tabularx}
    end{minipage}quad
    begin{minipage}{.2linewidth}
    begin{align*}
    &numprint[dm^2]{4}\
    &=numprint[mm^2]{40000}\
    &=numprint[m^2]{0,04}
    end{align*}
    end{minipage}

    end{document}


    In the numprint manual, there is a hack that allows you to color the negative numbers on pages 18-19, I couldn't modify it to write the numbers in blue.



    makeatletter
    expandafterrenewcommandcsname nprt@sign@-endcsname{%
    color{red}{ensuremath{-}}}
    makeatother









    share|improve this question

























      5












      5








      5







      This question is related to this one: Colour only the text in a tabularx environment



      I want to write as a succession of equality in blue (only the numbers) so that each line of the table has a corresponding equality line to its right.



      capture



      documentclass{article}
      usepackage{amsmath,numprint,tabularx,xcolor}

      begin{document}
      begin{minipage}{.4linewidth}
      begin{tabularx}{5cm}{|*{11}{>{leavevmodecolor{blue}}X|}}
      hline
      multicolumn{2}{|c|}{$rm m^2$} &
      multicolumn{2}{c|}{$rm dm^2$} &
      multicolumn{2}{c|}{$rm cm^2$} &
      multicolumn{2}{c|}{$rm mm^2$} \
      hline
      &&&4,&&&& \
      &&&4&0&0&0& 0,\
      &0,&0&4&&&& \
      hline
      end{tabularx}
      end{minipage}quad
      begin{minipage}{.2linewidth}
      begin{align*}
      &numprint[dm^2]{4}\
      &=numprint[mm^2]{40000}\
      &=numprint[m^2]{0,04}
      end{align*}
      end{minipage}

      end{document}


      In the numprint manual, there is a hack that allows you to color the negative numbers on pages 18-19, I couldn't modify it to write the numbers in blue.



      makeatletter
      expandafterrenewcommandcsname nprt@sign@-endcsname{%
      color{red}{ensuremath{-}}}
      makeatother









      share|improve this question













      This question is related to this one: Colour only the text in a tabularx environment



      I want to write as a succession of equality in blue (only the numbers) so that each line of the table has a corresponding equality line to its right.



      capture



      documentclass{article}
      usepackage{amsmath,numprint,tabularx,xcolor}

      begin{document}
      begin{minipage}{.4linewidth}
      begin{tabularx}{5cm}{|*{11}{>{leavevmodecolor{blue}}X|}}
      hline
      multicolumn{2}{|c|}{$rm m^2$} &
      multicolumn{2}{c|}{$rm dm^2$} &
      multicolumn{2}{c|}{$rm cm^2$} &
      multicolumn{2}{c|}{$rm mm^2$} \
      hline
      &&&4,&&&& \
      &&&4&0&0&0& 0,\
      &0,&0&4&&&& \
      hline
      end{tabularx}
      end{minipage}quad
      begin{minipage}{.2linewidth}
      begin{align*}
      &numprint[dm^2]{4}\
      &=numprint[mm^2]{40000}\
      &=numprint[m^2]{0,04}
      end{align*}
      end{minipage}

      end{document}


      In the numprint manual, there is a hack that allows you to color the negative numbers on pages 18-19, I couldn't modify it to write the numbers in blue.



      makeatletter
      expandafterrenewcommandcsname nprt@sign@-endcsname{%
      color{red}{ensuremath{-}}}
      makeatother






      color numprint






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 27 '18 at 16:41









      AndréC

      8,02511443




      8,02511443






















          2 Answers
          2






          active

          oldest

          votes


















          5














          You can locally patch numprint to set color{black} for the optional argument.



          Note that tabularx is not the right tool for the job.



          documentclass{article}
          usepackage{amsmath,numprint,array,xcolor,xpatch}

          begin{document}

          begingroup
          makeatletter
          xpatchcmd{numprint}
          {defnprt@oarg{#1}}
          {defnprt@oarg{color{black}#1}}
          {}{}
          makeatother

          begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}>{color{blue}}l }
          cline{1-8}
          multicolumn{2}{|c|}{$mathrm{m}^2vphantom{Big|}$} &
          multicolumn{2}{c|}{$mathrm{dm}^2$} &
          multicolumn{2}{c|}{$mathrm{cm}^2$} &
          multicolumn{2}{c|}{$mathrm{mm}^2$} \
          cline{1-8}
          &&&4rlap{,}&&&&& numprint[dm^2]{4} \
          &&&4&0&0&0& 0rlap{,} &= numprint[cm^2]{40000} \
          &0rlap{,}&0&4&&&&& = numprint[m^2]{0,04} \
          cline{1-8}
          end{tabular}
          endgroup

          end{document}


          enter image description here



          With siunitx:



          documentclass{article}
          usepackage{amsmath,siunitx,xcolor}

          sisetup{
          output-decimal-marker={,},
          power-font=unit,
          }

          begin{document}

          begingroup
          sisetup{
          number-color=blue,
          }
          begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}l }
          cline{1-8}
          multicolumn{2}{|c|}{si{squaremeter}$vphantom{Big|}$} &
          multicolumn{2}{c|}{si{squaredecimeter}} &
          multicolumn{2}{c|}{si{squarecentimeter}} &
          multicolumn{2}{c|}{si{squaremillimeter}} \
          cline{1-8}
          &&&4rlap{,}&&&&& SI{4}{squaredecimeter} \
          &&&4&0&0&0& 0rlap{,} &= SI{40000}{squarecentimeter} \
          &0rlap{,}&0&4&&&&& = SI{0,04}{squaremeter} \
          cline{1-8}
          end{tabular}
          endgroup

          end{document}


          enter image description here






          share|improve this answer























          • Why is tabularx not appropriate here? However, it allows to obtain columns of the same width, which is necessary here.
            – AndréC
            Dec 27 '18 at 18:35










          • @AndréC Aren't the column the same width here?
            – egreg
            Dec 27 '18 at 18:37










          • Yes, they are, but generally with tabular, they adapt. Why are they the same width here with tabular?
            – AndréC
            Dec 27 '18 at 18:40






          • 1




            @AndréC I used w{c}{1em}, which is exactly how to make a 1em wide column with center alignment; (requires array). The comma is “hidden” by rlap.
            – egreg
            Dec 27 '18 at 18:50






          • 1




            @AndréC In this case, tabularx is not the right tool because you don't know the target width; if you have several similar tables to this one, the width of the digit columns should be the same across the document
            – egreg
            yesterday



















          5














          Here's an option using a single tabular for better vertical alignment:



          enter image description here



          documentclass{article}

          usepackage{numprint,xcolor}

          begin{document}

          begin{tabular}{| *{8}{>{color{blue}}l|} >{color{blue}} l }
          cline{1-8}
          multicolumn{2}{|c|}{$mathrm{m}^2$rule{0pt}{normalbaselineskip}} & % added some vertical padding
          multicolumn{2}{c|}{$mathrm{dm}^2$} &
          multicolumn{2}{c|}{$mathrm{cm}^2$} &
          multicolumn{2}{c|}{$mathrm{mm}^2$} \
          cline{1-8}
          phantom{0,} & & & 4, & & & & & {} phantom{=} numprint[color{black}dm^2]{4} \
          & & & 4 & 0 & 0 & 0 & 0, & {} {color{black}=} numprint[color{black}mm^2]{40000} \
          & 0, & 0 & 4 & & & & & {} {color{black}=} numprint[color{black}m^2]{0,04} \
          cline{1-8}
          end{tabular}

          end{document}


          The entire numprint-column is set in color{blue} with each unit set in color{black} (as well as the =).






          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%2f467560%2fhow-to-change-only-the-color-of-numbers-and-not-units-with-numprint%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









            5














            You can locally patch numprint to set color{black} for the optional argument.



            Note that tabularx is not the right tool for the job.



            documentclass{article}
            usepackage{amsmath,numprint,array,xcolor,xpatch}

            begin{document}

            begingroup
            makeatletter
            xpatchcmd{numprint}
            {defnprt@oarg{#1}}
            {defnprt@oarg{color{black}#1}}
            {}{}
            makeatother

            begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}>{color{blue}}l }
            cline{1-8}
            multicolumn{2}{|c|}{$mathrm{m}^2vphantom{Big|}$} &
            multicolumn{2}{c|}{$mathrm{dm}^2$} &
            multicolumn{2}{c|}{$mathrm{cm}^2$} &
            multicolumn{2}{c|}{$mathrm{mm}^2$} \
            cline{1-8}
            &&&4rlap{,}&&&&& numprint[dm^2]{4} \
            &&&4&0&0&0& 0rlap{,} &= numprint[cm^2]{40000} \
            &0rlap{,}&0&4&&&&& = numprint[m^2]{0,04} \
            cline{1-8}
            end{tabular}
            endgroup

            end{document}


            enter image description here



            With siunitx:



            documentclass{article}
            usepackage{amsmath,siunitx,xcolor}

            sisetup{
            output-decimal-marker={,},
            power-font=unit,
            }

            begin{document}

            begingroup
            sisetup{
            number-color=blue,
            }
            begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}l }
            cline{1-8}
            multicolumn{2}{|c|}{si{squaremeter}$vphantom{Big|}$} &
            multicolumn{2}{c|}{si{squaredecimeter}} &
            multicolumn{2}{c|}{si{squarecentimeter}} &
            multicolumn{2}{c|}{si{squaremillimeter}} \
            cline{1-8}
            &&&4rlap{,}&&&&& SI{4}{squaredecimeter} \
            &&&4&0&0&0& 0rlap{,} &= SI{40000}{squarecentimeter} \
            &0rlap{,}&0&4&&&&& = SI{0,04}{squaremeter} \
            cline{1-8}
            end{tabular}
            endgroup

            end{document}


            enter image description here






            share|improve this answer























            • Why is tabularx not appropriate here? However, it allows to obtain columns of the same width, which is necessary here.
              – AndréC
              Dec 27 '18 at 18:35










            • @AndréC Aren't the column the same width here?
              – egreg
              Dec 27 '18 at 18:37










            • Yes, they are, but generally with tabular, they adapt. Why are they the same width here with tabular?
              – AndréC
              Dec 27 '18 at 18:40






            • 1




              @AndréC I used w{c}{1em}, which is exactly how to make a 1em wide column with center alignment; (requires array). The comma is “hidden” by rlap.
              – egreg
              Dec 27 '18 at 18:50






            • 1




              @AndréC In this case, tabularx is not the right tool because you don't know the target width; if you have several similar tables to this one, the width of the digit columns should be the same across the document
              – egreg
              yesterday
















            5














            You can locally patch numprint to set color{black} for the optional argument.



            Note that tabularx is not the right tool for the job.



            documentclass{article}
            usepackage{amsmath,numprint,array,xcolor,xpatch}

            begin{document}

            begingroup
            makeatletter
            xpatchcmd{numprint}
            {defnprt@oarg{#1}}
            {defnprt@oarg{color{black}#1}}
            {}{}
            makeatother

            begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}>{color{blue}}l }
            cline{1-8}
            multicolumn{2}{|c|}{$mathrm{m}^2vphantom{Big|}$} &
            multicolumn{2}{c|}{$mathrm{dm}^2$} &
            multicolumn{2}{c|}{$mathrm{cm}^2$} &
            multicolumn{2}{c|}{$mathrm{mm}^2$} \
            cline{1-8}
            &&&4rlap{,}&&&&& numprint[dm^2]{4} \
            &&&4&0&0&0& 0rlap{,} &= numprint[cm^2]{40000} \
            &0rlap{,}&0&4&&&&& = numprint[m^2]{0,04} \
            cline{1-8}
            end{tabular}
            endgroup

            end{document}


            enter image description here



            With siunitx:



            documentclass{article}
            usepackage{amsmath,siunitx,xcolor}

            sisetup{
            output-decimal-marker={,},
            power-font=unit,
            }

            begin{document}

            begingroup
            sisetup{
            number-color=blue,
            }
            begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}l }
            cline{1-8}
            multicolumn{2}{|c|}{si{squaremeter}$vphantom{Big|}$} &
            multicolumn{2}{c|}{si{squaredecimeter}} &
            multicolumn{2}{c|}{si{squarecentimeter}} &
            multicolumn{2}{c|}{si{squaremillimeter}} \
            cline{1-8}
            &&&4rlap{,}&&&&& SI{4}{squaredecimeter} \
            &&&4&0&0&0& 0rlap{,} &= SI{40000}{squarecentimeter} \
            &0rlap{,}&0&4&&&&& = SI{0,04}{squaremeter} \
            cline{1-8}
            end{tabular}
            endgroup

            end{document}


            enter image description here






            share|improve this answer























            • Why is tabularx not appropriate here? However, it allows to obtain columns of the same width, which is necessary here.
              – AndréC
              Dec 27 '18 at 18:35










            • @AndréC Aren't the column the same width here?
              – egreg
              Dec 27 '18 at 18:37










            • Yes, they are, but generally with tabular, they adapt. Why are they the same width here with tabular?
              – AndréC
              Dec 27 '18 at 18:40






            • 1




              @AndréC I used w{c}{1em}, which is exactly how to make a 1em wide column with center alignment; (requires array). The comma is “hidden” by rlap.
              – egreg
              Dec 27 '18 at 18:50






            • 1




              @AndréC In this case, tabularx is not the right tool because you don't know the target width; if you have several similar tables to this one, the width of the digit columns should be the same across the document
              – egreg
              yesterday














            5












            5








            5






            You can locally patch numprint to set color{black} for the optional argument.



            Note that tabularx is not the right tool for the job.



            documentclass{article}
            usepackage{amsmath,numprint,array,xcolor,xpatch}

            begin{document}

            begingroup
            makeatletter
            xpatchcmd{numprint}
            {defnprt@oarg{#1}}
            {defnprt@oarg{color{black}#1}}
            {}{}
            makeatother

            begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}>{color{blue}}l }
            cline{1-8}
            multicolumn{2}{|c|}{$mathrm{m}^2vphantom{Big|}$} &
            multicolumn{2}{c|}{$mathrm{dm}^2$} &
            multicolumn{2}{c|}{$mathrm{cm}^2$} &
            multicolumn{2}{c|}{$mathrm{mm}^2$} \
            cline{1-8}
            &&&4rlap{,}&&&&& numprint[dm^2]{4} \
            &&&4&0&0&0& 0rlap{,} &= numprint[cm^2]{40000} \
            &0rlap{,}&0&4&&&&& = numprint[m^2]{0,04} \
            cline{1-8}
            end{tabular}
            endgroup

            end{document}


            enter image description here



            With siunitx:



            documentclass{article}
            usepackage{amsmath,siunitx,xcolor}

            sisetup{
            output-decimal-marker={,},
            power-font=unit,
            }

            begin{document}

            begingroup
            sisetup{
            number-color=blue,
            }
            begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}l }
            cline{1-8}
            multicolumn{2}{|c|}{si{squaremeter}$vphantom{Big|}$} &
            multicolumn{2}{c|}{si{squaredecimeter}} &
            multicolumn{2}{c|}{si{squarecentimeter}} &
            multicolumn{2}{c|}{si{squaremillimeter}} \
            cline{1-8}
            &&&4rlap{,}&&&&& SI{4}{squaredecimeter} \
            &&&4&0&0&0& 0rlap{,} &= SI{40000}{squarecentimeter} \
            &0rlap{,}&0&4&&&&& = SI{0,04}{squaremeter} \
            cline{1-8}
            end{tabular}
            endgroup

            end{document}


            enter image description here






            share|improve this answer














            You can locally patch numprint to set color{black} for the optional argument.



            Note that tabularx is not the right tool for the job.



            documentclass{article}
            usepackage{amsmath,numprint,array,xcolor,xpatch}

            begin{document}

            begingroup
            makeatletter
            xpatchcmd{numprint}
            {defnprt@oarg{#1}}
            {defnprt@oarg{color{black}#1}}
            {}{}
            makeatother

            begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}>{color{blue}}l }
            cline{1-8}
            multicolumn{2}{|c|}{$mathrm{m}^2vphantom{Big|}$} &
            multicolumn{2}{c|}{$mathrm{dm}^2$} &
            multicolumn{2}{c|}{$mathrm{cm}^2$} &
            multicolumn{2}{c|}{$mathrm{mm}^2$} \
            cline{1-8}
            &&&4rlap{,}&&&&& numprint[dm^2]{4} \
            &&&4&0&0&0& 0rlap{,} &= numprint[cm^2]{40000} \
            &0rlap{,}&0&4&&&&& = numprint[m^2]{0,04} \
            cline{1-8}
            end{tabular}
            endgroup

            end{document}


            enter image description here



            With siunitx:



            documentclass{article}
            usepackage{amsmath,siunitx,xcolor}

            sisetup{
            output-decimal-marker={,},
            power-font=unit,
            }

            begin{document}

            begingroup
            sisetup{
            number-color=blue,
            }
            begin{tabular}{ |*{8}{>{color{blue}}w{c}{1em}|}l }
            cline{1-8}
            multicolumn{2}{|c|}{si{squaremeter}$vphantom{Big|}$} &
            multicolumn{2}{c|}{si{squaredecimeter}} &
            multicolumn{2}{c|}{si{squarecentimeter}} &
            multicolumn{2}{c|}{si{squaremillimeter}} \
            cline{1-8}
            &&&4rlap{,}&&&&& SI{4}{squaredecimeter} \
            &&&4&0&0&0& 0rlap{,} &= SI{40000}{squarecentimeter} \
            &0rlap{,}&0&4&&&&& = SI{0,04}{squaremeter} \
            cline{1-8}
            end{tabular}
            endgroup

            end{document}


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 27 '18 at 18:50

























            answered Dec 27 '18 at 18:08









            egreg

            710k8618853168




            710k8618853168












            • Why is tabularx not appropriate here? However, it allows to obtain columns of the same width, which is necessary here.
              – AndréC
              Dec 27 '18 at 18:35










            • @AndréC Aren't the column the same width here?
              – egreg
              Dec 27 '18 at 18:37










            • Yes, they are, but generally with tabular, they adapt. Why are they the same width here with tabular?
              – AndréC
              Dec 27 '18 at 18:40






            • 1




              @AndréC I used w{c}{1em}, which is exactly how to make a 1em wide column with center alignment; (requires array). The comma is “hidden” by rlap.
              – egreg
              Dec 27 '18 at 18:50






            • 1




              @AndréC In this case, tabularx is not the right tool because you don't know the target width; if you have several similar tables to this one, the width of the digit columns should be the same across the document
              – egreg
              yesterday


















            • Why is tabularx not appropriate here? However, it allows to obtain columns of the same width, which is necessary here.
              – AndréC
              Dec 27 '18 at 18:35










            • @AndréC Aren't the column the same width here?
              – egreg
              Dec 27 '18 at 18:37










            • Yes, they are, but generally with tabular, they adapt. Why are they the same width here with tabular?
              – AndréC
              Dec 27 '18 at 18:40






            • 1




              @AndréC I used w{c}{1em}, which is exactly how to make a 1em wide column with center alignment; (requires array). The comma is “hidden” by rlap.
              – egreg
              Dec 27 '18 at 18:50






            • 1




              @AndréC In this case, tabularx is not the right tool because you don't know the target width; if you have several similar tables to this one, the width of the digit columns should be the same across the document
              – egreg
              yesterday
















            Why is tabularx not appropriate here? However, it allows to obtain columns of the same width, which is necessary here.
            – AndréC
            Dec 27 '18 at 18:35




            Why is tabularx not appropriate here? However, it allows to obtain columns of the same width, which is necessary here.
            – AndréC
            Dec 27 '18 at 18:35












            @AndréC Aren't the column the same width here?
            – egreg
            Dec 27 '18 at 18:37




            @AndréC Aren't the column the same width here?
            – egreg
            Dec 27 '18 at 18:37












            Yes, they are, but generally with tabular, they adapt. Why are they the same width here with tabular?
            – AndréC
            Dec 27 '18 at 18:40




            Yes, they are, but generally with tabular, they adapt. Why are they the same width here with tabular?
            – AndréC
            Dec 27 '18 at 18:40




            1




            1




            @AndréC I used w{c}{1em}, which is exactly how to make a 1em wide column with center alignment; (requires array). The comma is “hidden” by rlap.
            – egreg
            Dec 27 '18 at 18:50




            @AndréC I used w{c}{1em}, which is exactly how to make a 1em wide column with center alignment; (requires array). The comma is “hidden” by rlap.
            – egreg
            Dec 27 '18 at 18:50




            1




            1




            @AndréC In this case, tabularx is not the right tool because you don't know the target width; if you have several similar tables to this one, the width of the digit columns should be the same across the document
            – egreg
            yesterday




            @AndréC In this case, tabularx is not the right tool because you don't know the target width; if you have several similar tables to this one, the width of the digit columns should be the same across the document
            – egreg
            yesterday











            5














            Here's an option using a single tabular for better vertical alignment:



            enter image description here



            documentclass{article}

            usepackage{numprint,xcolor}

            begin{document}

            begin{tabular}{| *{8}{>{color{blue}}l|} >{color{blue}} l }
            cline{1-8}
            multicolumn{2}{|c|}{$mathrm{m}^2$rule{0pt}{normalbaselineskip}} & % added some vertical padding
            multicolumn{2}{c|}{$mathrm{dm}^2$} &
            multicolumn{2}{c|}{$mathrm{cm}^2$} &
            multicolumn{2}{c|}{$mathrm{mm}^2$} \
            cline{1-8}
            phantom{0,} & & & 4, & & & & & {} phantom{=} numprint[color{black}dm^2]{4} \
            & & & 4 & 0 & 0 & 0 & 0, & {} {color{black}=} numprint[color{black}mm^2]{40000} \
            & 0, & 0 & 4 & & & & & {} {color{black}=} numprint[color{black}m^2]{0,04} \
            cline{1-8}
            end{tabular}

            end{document}


            The entire numprint-column is set in color{blue} with each unit set in color{black} (as well as the =).






            share|improve this answer




























              5














              Here's an option using a single tabular for better vertical alignment:



              enter image description here



              documentclass{article}

              usepackage{numprint,xcolor}

              begin{document}

              begin{tabular}{| *{8}{>{color{blue}}l|} >{color{blue}} l }
              cline{1-8}
              multicolumn{2}{|c|}{$mathrm{m}^2$rule{0pt}{normalbaselineskip}} & % added some vertical padding
              multicolumn{2}{c|}{$mathrm{dm}^2$} &
              multicolumn{2}{c|}{$mathrm{cm}^2$} &
              multicolumn{2}{c|}{$mathrm{mm}^2$} \
              cline{1-8}
              phantom{0,} & & & 4, & & & & & {} phantom{=} numprint[color{black}dm^2]{4} \
              & & & 4 & 0 & 0 & 0 & 0, & {} {color{black}=} numprint[color{black}mm^2]{40000} \
              & 0, & 0 & 4 & & & & & {} {color{black}=} numprint[color{black}m^2]{0,04} \
              cline{1-8}
              end{tabular}

              end{document}


              The entire numprint-column is set in color{blue} with each unit set in color{black} (as well as the =).






              share|improve this answer


























                5












                5








                5






                Here's an option using a single tabular for better vertical alignment:



                enter image description here



                documentclass{article}

                usepackage{numprint,xcolor}

                begin{document}

                begin{tabular}{| *{8}{>{color{blue}}l|} >{color{blue}} l }
                cline{1-8}
                multicolumn{2}{|c|}{$mathrm{m}^2$rule{0pt}{normalbaselineskip}} & % added some vertical padding
                multicolumn{2}{c|}{$mathrm{dm}^2$} &
                multicolumn{2}{c|}{$mathrm{cm}^2$} &
                multicolumn{2}{c|}{$mathrm{mm}^2$} \
                cline{1-8}
                phantom{0,} & & & 4, & & & & & {} phantom{=} numprint[color{black}dm^2]{4} \
                & & & 4 & 0 & 0 & 0 & 0, & {} {color{black}=} numprint[color{black}mm^2]{40000} \
                & 0, & 0 & 4 & & & & & {} {color{black}=} numprint[color{black}m^2]{0,04} \
                cline{1-8}
                end{tabular}

                end{document}


                The entire numprint-column is set in color{blue} with each unit set in color{black} (as well as the =).






                share|improve this answer














                Here's an option using a single tabular for better vertical alignment:



                enter image description here



                documentclass{article}

                usepackage{numprint,xcolor}

                begin{document}

                begin{tabular}{| *{8}{>{color{blue}}l|} >{color{blue}} l }
                cline{1-8}
                multicolumn{2}{|c|}{$mathrm{m}^2$rule{0pt}{normalbaselineskip}} & % added some vertical padding
                multicolumn{2}{c|}{$mathrm{dm}^2$} &
                multicolumn{2}{c|}{$mathrm{cm}^2$} &
                multicolumn{2}{c|}{$mathrm{mm}^2$} \
                cline{1-8}
                phantom{0,} & & & 4, & & & & & {} phantom{=} numprint[color{black}dm^2]{4} \
                & & & 4 & 0 & 0 & 0 & 0, & {} {color{black}=} numprint[color{black}mm^2]{40000} \
                & 0, & 0 & 4 & & & & & {} {color{black}=} numprint[color{black}m^2]{0,04} \
                cline{1-8}
                end{tabular}

                end{document}


                The entire numprint-column is set in color{blue} with each unit set in color{black} (as well as the =).







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 27 '18 at 17:36

























                answered Dec 27 '18 at 17:21









                Werner

                438k649611653




                438k649611653






























                    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%2f467560%2fhow-to-change-only-the-color-of-numbers-and-not-units-with-numprint%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?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

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