2

A couple weeks ago, this tikzpicture is produced nicely so I assume I have no problem anymore with it and get into the writting part. But when I checked the picture a couple days ago, the picture become look like this: enter image description here

I assume the error is on the \if, but when I try to reproduce it on a new tex project using the same custom class, the tikz picture is drawn nicely.

There are so many addition after that, so I don't know the reason why I can face this strange behaviour. Could somebody help me find the problem?

This is the code:

\begin{figure}[htbp]
\centering
\begin{adjustbox}{max width=\textwidth}
\tikzset{
    neuron/.style={shape=circle, minimum size=1.25cm, inner sep=0, draw, font=\small},
    rct/.style={draw, font=\small, inner sep=0, minimum size=1.25cm, shape=rectangle},
    ttk/.style={draw=none, scale=2},
}
\begin{tikzpicture}[x=2.2cm, y=1.5cm, >=Stealth]
  \foreach \t [count=\ti, evaluate={\ta=int(\ti-1);}] in {-1, 1, 2, 3, \ldots, T, -1}{
    \if\t=\ldots
        \node [ttk] at (\ti,1) (h-\ti) {\ldots};
    \else
      \ifnum\ti=1
        \node [ttk] at (\ti, 1) (h-\ti) {};
      \else
        \ifnum\ti=7
          \node [ttk] at (\ti, 1) (h-\ti) {};
        \else
            \node [rct] at (\ti,1) (h-\ti){$\mathbf h_{\t}$};
            \node [rct, below=of h-\ti] (x-\t) {$\mathbf x_{\t}$};
            \node [rct, above=of h-\ti] (y-\t) {$\mathbf y_{\t}$};
            \draw [->] (x-\t) -- (h-\ti);
          \draw [->] (h-\ti) -- (y-\t);
        \fi
      \fi
    \fi
    \ifnum\ti>1
      \draw [->] (h-\ta.east) -- (h-\ti.west);
    \fi
  }
\end{tikzpicture}
\end{adjustbox}
\caption{Some caption}
\label{img:my-arsitektur}
\end{figure}

This is the reproduced picture (and was the picture before the problem arise): enter image description here

[EDIT]

I just found the cause of this strange behavior, and can resolve my problem. But I still open this question for the explanation why such thing can make the tikz picture have a strange behavior.

This is the main cause: I put this on my tex

\firstexaminer{\ldots}

and the definition on the class is:

\newcommand{\firstexaminer}[1]{\gdef\@firstexaminer{#1}}%
\newcommand{\@firstexaminer}{}

where the use of that command is on this part of class:

\def\approvalpage{%
 \newpage\thispagestyle{empty}%
  \begin{center}
  \begin{singlespace}
  \MakeUppercase{\normalfont\large\bfseries\expandafter{Halaman Pengesahan}}\\
  \vspace{1.0cm}
  \MakeUppercase{\normalfont\large\bfseries\expandafter{Skripsi}}\\
  \vspace{0.5cm}
      \MakeUppercase{\normalfont\bfseries\@titleind}\par\nobreak
  \vspace{1.0cm}
Telah dipersiapkan dan disusun oleh\\
\vspace{0.5cm}
\MakeUppercase{\@fullname}\\
\@idnum\\
\vspace{1.0cm}
Telah dipertahankan di depan Tim Penguji\\
pada tanggal \expandafter{\@examdate}\\
\vspace{0.5cm}
Susunan Tim Penguji\\
\vspace{2.2cm}
\begin{tabular}{p{8cm}p{6cm}}
\@firstsupervisor&\@firstexaminer\\
Pembimbing&Ketua Penguji
\end{tabular}

\vspace{2.0cm}
\begin{tabular}{p{8cm}p{6cm}}
\@secondsupervisor&\@secondexaminer\\
&Anggota Penguji
\end{tabular}

\bigskip
\vspace{2.0cm}
\begin{tabular}{p{8cm}p{6cm}}
&\@thirdexaminer\\
&
\end{tabular}
    \end{singlespace}
    \end{center}
\addcontentsline{toc}{chapter}{Halaman Pengesahan}
}

when I change the \ldots to a real character on

\firstexaminer{John Doe}

The \if inside tikzpicture is working like a charm.


this is the class file: https://github.com/muhrifqii/skripsi-fmipa-ugm-latex/blob/master/ugmskripsi.cls

  • 2
    if you want help with an error please always post a test file that reproduces the error so people can debug it. Disconnected fragments are much harder to debug and force anyone helping to try to guess how you used those fragments in a document – David Carlisle May 8 '17 at 6:52
  • thanks @DavidCarlisle , I have edited the question for the class file – Muhammad Rifqi Fatchurrahman May 8 '17 at 8:14
4
\if\t=\ldots

expands \t and then tests the charter codes of the first two characters

so if \t was aa it would be true, if \t was ab it would be false. If \t has just one character then it would be tested against the = so just true if it is =. If \t is empty then the test will test if the frirst character in the expansion of \ldots is =.

Probably you want

\ifx\t\zldots

where \zldots is defined by

\def\zldots{\ldots}
4

Here is a much easier way of doing this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}

  \begin{tikzpicture}[rct/.style={draw, font=\small, inner sep=0, minimum size=8mm, shape=rectangle},
                      scale=1.5,
                      >=Stealth]
    \foreach \row[count=\y] in {x, h, y} {
       \foreach \x/\sub in {1/1, 2/2, 3/3, 5/T} {
           \node[rct](\row\x) at (\x,\y) {$\row_{\sub}$};
        }
    };
    \foreach \x in {1,2,3,5} {
        \draw[->] (x\x) -- (h\x);
        \draw[->] (h\x) -- (y\x);
    };
    \coordinate (h0) at (0,2);
    \coordinate (h6) at (6,2);
    \node[shape=rectangle, inner sep=0, minimum size=8mm] (h4) at (4,2) {$\cdots$};
    \foreach \x [evaluate=\x as \xx using int(\x+1)] in {0, ..., 5} {
        \draw[->] (h\x) -- (h\xx);
    };
  \end{tikzpicture}

\end{document}

As above, this produces:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.