Pude armar una tabla de valores trigonométricos usando expl3
. Sin embargo, me gustaría rellenar ceros hasta el final para que todos los valores tengan cuatro decimales. ¿Existe una forma sencilla de hacer esto expl3
o necesito crear mi propia macro para manejar esto?
Esto está relacionado con una pregunta similar que acabo de publicar:¿Existe una forma sencilla de mejorar la precisión de pgfmath para funciones trigonométricas?
Aquí está mi MWE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\mynum{0}
\def\myvoffset{0pt}
\usepackage{xparse}
\ExplSyntaxOn
\def\aetan#1{\fp_eval:n { round ( tand ( #1 ), 4 )}}
\def\aesin#1{\fp_eval:n { round ( sind ( #1 ), 4 )}}
\def\aecos#1{\fp_eval:n { round ( cosd ( #1 ), 4 )}}
\def\aemod#1{\fp_eval:n { #1 - round0 ( #1 / 5 , 0 ) * 5}}
\ExplSyntaxOff
\usepackage[margin=0.5in]{geometry}
\begin{document}
Using \LaTeX3
\begin{tikzpicture}
\coordinate(UL) at (0,0);
\node at (UL) {Degrees};
\node[anchor=west] at ($(UL.west)+(1cm,0)$) {$\sin$};
\node[anchor=west] at ($(UL.west)+(2.75cm,0)$) {$\cos$};
\node[anchor=west] at ($(UL.west)+(4.50cm,0)$) {$\tan$};
\foreach \myn in {1,2,3,...,45}
{
\ifnum\aemod{(\myn-1)}=0\relax
\xdef\myvoffset{\dimexpr\myvoffset+1.350\baselineskip}%%
\else
\xdef\myvoffset{\dimexpr\myvoffset+1.00\baselineskip}%%
\fi
\coordinate (DEG/\myn) at ($(UL.west)-(0,\myvoffset)$);
\coordinate (DEG/S/\myn) at ($(DEG/\myn)+(1cm,0)$);
\coordinate (DEG/C/\myn) at ($(DEG/S/\myn)+(1.75cm,0)$);
\coordinate (DEG/T/\myn) at ($(DEG/C/\myn)+(1.75cm,0)$);
\node[anchor=east] at (DEG/\myn) {$\myn^\circ$};
\node[anchor=west] at (DEG/S/\myn) {\texttt{\aesin{\myn}}};
\node[anchor=west] at (DEG/C/\myn) {\texttt{\aecos{\myn}}};
\node[anchor=west] at (DEG/T/\myn) {\texttt{\aetan{\myn}}};
}
\end{tikzpicture}
\end{document}
Respuesta1
He encontrado una especie de solución, aunque no es una expl3
solución. Utilizo el siunitx
paquete de la siguiente manera:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{siunitx}
\sisetup{add-decimal-zero,
round-precision=4,
round-mode=places,
round-integer-to-decimal,
detect-all}
\def\mynum{0}
\def\myvoffset{0pt}
\usepackage{xparse}
\ExplSyntaxOn
\def\aetan#1{\num{\fp_eval:n { round ( tand ( #1 ), 4 )}}}
\def\aesin#1{\num{\fp_eval:n { round ( sind ( #1 ), 4 )}}}
\def\aecos#1{\num{\fp_eval:n { round ( cosd ( #1 ), 4 )}}}
\def\aemod#1{\fp_eval:n { #1 - round0 ( #1 / 5 , 0 ) * 5}}
\ExplSyntaxOff
\usepackage[margin=0.5in]{geometry}
\begin{document}
Using \LaTeX3
\begin{tikzpicture}
\coordinate(UL) at (0,0);
\node at (UL) {Degrees};
\node[anchor=west] at ($(UL.west)+(1cm,0)$) {$\sin$};
\node[anchor=west] at ($(UL.west)+(2.75cm,0)$) {$\cos$};
\node[anchor=west] at ($(UL.west)+(4.50cm,0)$) {$\tan$};
\foreach \myn in {1,2,3,...,45}
{
\ifnum\aemod{(\myn-1)}=0\relax
\xdef\myvoffset{\dimexpr\myvoffset+1.350\baselineskip}%%
\else
\xdef\myvoffset{\dimexpr\myvoffset+1.00\baselineskip}%%
\fi
\coordinate (DEG/\myn) at ($(UL.west)-(0,\myvoffset)$);
\coordinate (SIN/\myn) at ($(DEG/\myn)+(1cm,0)$);
\coordinate (COS/\myn) at ($(SIN/\myn)+(1.75cm,0)$);
\coordinate (TAN/\myn) at ($(COS/\myn)+(1.75cm,0)$);
\node[anchor=east] at (DEG/\myn) {$\myn^\circ$};
\node[anchor=west] at (SIN/\myn) {\texttt{\aesin{\myn}}};
\node[anchor=west] at (COS/\myn) {\texttt{\aecos{\myn}}};
\node[anchor=west] at (TAN/\myn) {\texttt{\aetan{\myn}}};
}
\end{tikzpicture}
\end{document}