Is there a way to change the default length unit in tikz to the ex unit? I have trouble while calculating complicated coordinates in tikz when I'm using the ex unit (I always get an error or a wrong result). However, as soon as I get rid of the length unit, I do more complicated computations with parenthesis involved and won't get any errors. I thought maybe if I can set ex to be the default length unit and drop it in the syntax, I can still work with this unit and won't run into the errors.
Changing the default length unit in tikz
calculationscoordinateslengthstikz-pgf
Related Solutions
PGF has the \pgfmathprintnumber
macro that allows you to print and format numbers, including rounding. To round to two decimal digits, you would use \pgfmathprintnumber[precision=2]{\pgfmathresult}
, for example.
The unit vectors are stored in \pgf@xx
(for the x-component of the x unit vector) and \pgf@yy
(the y-component of the y unit vector). So your function could be shortened to
\makeatletter
\newcommand\xcoord[2][center]{{%
\pgfpointanchor{#2}{#1}%
\pgfmathparse{\pgf@x/\pgf@xx}%
\pgfmathprintnumber{\pgfmathresult}%
}}
\newcommand\ycoord[2][center]{{%
\pgfpointanchor{#2}{#1}%
\pgfmathparse{\pgf@y/\pgf@yy}%
\pgfmathprintnumber{\pgfmathresult}%
}}
\makeatother
Is it some thing like this?
This is obtained by
\draw[dashed,line width=2pt] (aa.west) -- ++(-15pt,0) -- ++ (0,0,4)
-- ([xshift=-15pt]bb.west) -- (bb.west);
Code:
\documentclass[%
12pt,
journal,
onecolumn,
twoside,
draftcls,
letterpaper,
]{IEEEtran}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{3d}
\usepackage{adjustbox}
\usepackage{setspace} %\singlespacing
\usepackage{capt-of}
\usepackage[nopar]{lipsum}
\usepackage{xstring}
% http://tex.stackexchange.com/a/26808/2595
\makeatletter
\def\unpacklipsum#1#2#3{%
\count@=#1\relax
\advance\count@\m@ne
\def#3{}%
\loop\ifnum\count@<#2\relax
\advance\count@\@ne
\edef#3{#3\csname lipsum@\romannumeral\count@\endcsname}%
\repeat}
\makeatother
% http://tex.stackexchange.com/a/168754/2595
\def\loremnchars[#1]#2{%
\unpacklipsum{#1}{#1}{\myunpacked}%
\StrMid{\myunpacked}{1}{#2}% same as \StrLeft{\myunpacked}{#2}
}
\begin{document}
\loremnchars[1]{255} ...
\begin{center}
\singlespacing
\begin{adjustbox}{width=0.9\textwidth}
\def\angl{70}
\begin{tikzpicture}[
x={({cos(\angl)*1cm},{sin(\angl)*1cm})},y={(1.0cm,0cm)},z={(0,1cm)},
every node/.append style={
%xslant=0.0,yslant=0.0,
transform shape,
},
]
\tikzstyle{rr} = [draw,fill=gray,opacity=0.5];
\begin{scope}[canvas is yx plane at z=0.0]
\draw[rr] (0,0) rectangle (15,27);
\node[draw,align=left,anchor=south west] (aa) at (3,3.5) {\loremnchars[6]{60} \\ \loremnchars[7]{60}};
\end{scope}
\begin{scope}[canvas is yx plane at z=2.0]
\draw[rr] (0,0) rectangle (15,27);
\node[] (tdrag) at (7,24) {};
\begin{scope}[shift={(tdrag)},
rotate=180,
anchor=center,
transform shape,
]
\node[draw,align=left] {\loremnchars[2]{60} \\ \loremnchars[3]{60}};
\end{scope}
\end{scope}
\begin{scope}[canvas is yx plane at z=4.0]
\draw[rr] (0,0) rectangle (15,27);
\node[draw,align=left,anchor=south west] (bb) at (3,5.5) {\loremnchars[8]{60} \\ \loremnchars[9]{60}};
\end{scope}
% \draw[dashed,line width=2pt] (aa) -- (bb);
%\draw[line width=2pt] let \p1=(aa), \p2=(bb) in (\x1,\y1) ++(0,-50pt) -- (\x2,\y2); %L2
% \draw[dashed,line width=10pt] let \p1=(aa), \p2=(bb) in (\x1,\y1,0) -- (\x2,\y2,4); %L3
\draw[dashed,line width=2pt] (aa.west) -- ++(-15pt,0) -- ++ (0,0,4) -- ([xshift=-15pt]bb.west) -- (bb.west); %L2
\end{tikzpicture}
\end{adjustbox}
\captionof{figure}[short]{
A short message; \loremnchars[5]{255} ...
}
\label{fig:test}
\end{center}
\end{document}
Also, please note that caption
package is incompatible with IEEEtran
class. To get \captionof
macro, you may use capt-of
package as I did.
Best Answer
You can set the
x
andy
vectors:But notice that the
ex
unit is font-dependent, so it will change with the font in use outside thetikzpicture
(which is probably what you want, but...)