Search code examples
latex

Writing very small numbers in Latex figures


I have a basic figure where I want the following numbers to be in the Y axis 0.004,0.005,...,0.018

When I write them in the code they appear in a different way as you see in the screenshot. I know this is mathematically correct but they look odd and I want to them to be shown exactly as I put them in the code.

enter image description here

This is the code

\documentclass{article}
\usepackage{graphicx} % Required for inserting images

\usepackage{pgfplots}
\begin{document}

\begin{figure} 
\centering
\begin{tikzpicture} [style={outer sep=5}]
\begin{axis}[ymin=0.004,ymax=0.018, xmin=15, xmax=50,
xlabel= $Number of Nodes$, ylabel = $end-to-end (sec)$,
xtick={15,20,...,50},
ytick={0.004,0.005,...,0.018},
yticklabel style={/pgf/number format/fixed},
grid={major},clip=false,grid style={dashed},
title={},
legend style={at={(1.2 ,1)},anchor=north},
font=\footnotesize]

% TAODV
\addplot[color=blue, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates {
(15, 0.0072) +-(0.001, -0.001)
(20, 0.0079) +-(0.001, -0.001)
(25, 0.0092) +-(0.001, -0.001)
(30, 0.01) +-(0.001, -0.001)
(35, 0.013) +-(0.0018, -0.0018)
(40, 0.0137) +-(0.001, -0.001)
(45, 0.015) +-(0.001, -0.001)
(50, 0.0168)+-(0.001, -0.001)
};

% AODV
\addplot[color=red, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates {
(15, 0.0052) +-(0.001, -0.001)
(20, 0.0057) +-(0.001, -0.001)
(25, 0.0067) +-(0.001, -0.001)
(30, 0.0074) +-(0.001, -0.001)
(35, 0.0082) +-(0.0018, -0.0018)
(40, 0.0095) +-(0.001, -0.001)
(45, 0.01) +-(0.001, -0.001)
(50, 0.0109) +-(0.001, -0.001)
};

\legend{
    $TAODV$,
    $AODV$
}
\end{axis}
\end{tikzpicture}
\caption[End-to-end delay of TAODV vs. AODV]{End-to-end delay of TAODV vs. AODV with \%95 confidence interval}
\end{figure}

\end{document}

Solution

  • You can use scaled y ticks=false to switch off the common scaling factor. Please also note that math mode is a horrible choice for multi-letter words or even whole phrases.

    \documentclass{article}
    \usepackage{graphicx} % Required for inserting images
    
    \usepackage{pgfplots}
    \begin{document}
    
    \begin{figure} 
    \centering
    \begin{tikzpicture} [style={outer sep=5}]
    \begin{axis}[ymin=0.004,ymax=0.018, xmin=15, xmax=50,
    xlabel= \emph{Number of Nodes}, ylabel = \emph{end-to-end (sec)},
    xtick={15,20,...,50},
    ytick={0.004,0.005,...,0.018},
    grid={major},clip=false,grid style={dashed},
    title={},
    legend style={at={(1.2 ,1)},anchor=north},
    font=\footnotesize,
    scaled y ticks=false,
    yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},
    ]
    
    % TAODV
    \addplot[color=blue, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates {
    (15, 0.0072) +-(0.001, -0.001)
    (20, 0.0079) +-(0.001, -0.001)
    (25, 0.0092) +-(0.001, -0.001)
    (30, 0.01) +-(0.001, -0.001)
    (35, 0.013) +-(0.0018, -0.0018)
    (40, 0.0137) +-(0.001, -0.001)
    (45, 0.015) +-(0.001, -0.001)
    (50, 0.0168)+-(0.001, -0.001)
    };
    
    % AODV
    \addplot[color=red, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates {
    (15, 0.0052) +-(0.001, -0.001)
    (20, 0.0057) +-(0.001, -0.001)
    (25, 0.0067) +-(0.001, -0.001)
    (30, 0.0074) +-(0.001, -0.001)
    (35, 0.0082) +-(0.0018, -0.0018)
    (40, 0.0095) +-(0.001, -0.001)
    (45, 0.01) +-(0.001, -0.001)
    (50, 0.0109) +-(0.001, -0.001)
    };
    
    \legend{
        \emph{TAODV},
        \emph{AODV}
    }
    \end{axis}
    \end{tikzpicture}
    \caption[End-to-end delay of TAODV vs. AODV]{End-to-end delay of TAODV vs. AODV with \%95 confidence interval}
    \end{figure}
    
    \end{document}
    

    enter image description here