2

Consider this MWE:

\documentclass[%
12pt,
journal,
onecolumn,
twoside,
draftcls,
letterpaper,
]{IEEEtran}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{3d}
\usepackage{adjustbox}
\usepackage{setspace} %\singlespacing
\usepackage{caption}
\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[dashed,line width=2pt] let \p1=(aa), \p2=(bb) in (\x1,\y1) -- (\x2,\y2);      %L2
% \draw[dashed,line width=10pt] let \p1=(aa), \p2=(bb) in (\x1,\y1,0) -- (\x2,\y2,4); %L3

\end{tikzpicture}
\end{adjustbox}
\captionof{figure}[short]{
A short message; \loremnchars[5]{255} ...
}
\label{fig:test}
\end{center}

\end{document}

When I compile with the line %L2 enabled, as in the MWE, I get an expected result (click for full size):

test21

However, I would like a connector line that goes from (aa.west), then 5 pt to the left on same plane (z=0), then up to z=4, then left on same plane to (bb.west).

So I thought I'd simply use the let syntax, and extract the x, y coordinates from the node anchors, and simply add the z coordinate (and in-between points); but simply adding the z coordinate - if you uncomment line %L3 and comment %L2 - something weird is plotted:

test22

The line seems way off - I think the problem is: the \x1 coordinates are expressed in pt, and they are the transformed coordinates (as ultimately on the 2D paper); but for some reason, in the 3D node usage, they are probably still interpreted in cm (if I remember correctly, the default TikZ unit).

Regardless of the reason - is there any way I could use, so I can "convert" the \x1 and \y1 coordinates of, say (aa.east) in the "3D coordinate system", so I can use them directly with a manually specified Z coordinate?


EDIT: apparently this has something to do with cm conversion; with the code below (more or less found by bruteforcing), I get something close to what I want:

test23

Note that I have to both convert to cm, and invert the y and x coordinates to get this image, which puzzles me quite a bit. But it is not quite correct, it seems - the (bb) node should be directly above (aa); and yet if I follow the connector line, it looks like (bb) is displaced on y axis as well?? So still, a proper answer would be appreciated...

\documentclass[%
12pt,
journal,
onecolumn,
twoside,
draftcls,
letterpaper,
]{IEEEtran}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{3d}
\usepackage{adjustbox}
\usepackage{setspace} %\singlespacing
\usepackage{caption}
\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}
}

\makeatletter
% http://tex.stackexchange.com/questions/33703/extract-x-y-
\newcommand{\gettikzxy}[3]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \global\edef#2{\the\pgf@x}%
  \global\edef#3{\the\pgf@y}%
  \typeout{ gettikzxy: x #2, y #3}
}
% http://tex.stackexchange.com/a/8337/2595
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\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}};
    \gettikzxy{(aa.south west)}{\ax}{\ay}
  \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}};
    \gettikzxy{(bb.south west)}{\bx}{\by}
  \end{scope}

% \draw[dashed,line width=2pt] (aa) -- (bb);
% \draw[dashed,line width=2pt] let \p1=(aa), \p2=(bb) in (\x1,\y1) -- (\x2,\y2);      %L2
% \draw[dashed,line width=10pt] let \p1=(aa), \p2=(bb) in (\x1,\y1,0) -- (\x2,\y2,4); %L3

% \gettikzxy{(aa.south west)}{\ax}{\ay} % not here
\edef\cax{\convertto{cm}{\ax}}
\edef\cay{\convertto{cm}{\ay}}
\typeout{ : cax \cax, cay \cay }
\edef\cbx{\convertto{cm}{\bx}}
\edef\cby{\convertto{cm}{\by}}
\typeout{ : cbx \cbx, cby \cby }
\draw[dashed,line width=5pt] let
  \p1=(\cay,\cax,0),
  \p2=($(\p1)-(0pt,1pt,0)$),
  \p3=($(\p2)+(0,0,2)$),
  \p4=($(\p2)+(0,0,4)$),
  \p6=(\cby,\cbx,4),
  \p5=($(\p6)-(0,1pt,0)$)
  in
  (\p1) -- (\p2) node[fill]{} -- (\p3) node[fill]{} -- (\p4) node[fill]{} -- (\p5) -- (\p6) ;

\end{tikzpicture}
\end{adjustbox}
\captionof{figure}[short]{
A short message; \loremnchars[5]{255} ...
}
\label{fig:test}
\end{center}

\end{document}

1 Answer 1

3

Is it some thing like this?

enter image description here

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.

2
  • Many thanks for that, @HarishKumar - was a bit surprised when I saw that syntax, I would have thought it wouldn't work, but it does! I'm still confused so as to why the part ++ (0,0,4) -- ([xshift=-15pt]bb.west) generates a line along the "y" axis; both aa and bb are anchor=south west] at (3,5.5); so that line part should be zero length? Nevermind though, good to know this syntax works. Cheers!
    – sdaau
    Apr 5, 2014 at 23:59
  • 1
    @sdaau Glad it works :). May be because you have z={(0,1cm)}? :)
    – user11232
    Apr 6, 2014 at 0:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .