1

I successfully constructed a TikZ diagram with the following code

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows, shapes}

\begin{document}

\tikzset{rectangle state/.style={draw,rectangle}} % make rectangles available
\begin{tikzpicture}
  \node[state, minimum size=1.5cm] (y1) {$\mathbf{y}_{1}$};
  \node[rectangle state,minimum size=1.5cm] (x11) [below= of y1] {$x_{11}$};
  \node[rectangle state,minimum size=1.5cm] (x21) [below= of x11] {$\mathbf{x}_{21}$};
  \node[rectangle state, minimum size=1.5cm] (x31) [below= of x21] {$\mathbf{x}_{31}$};
  \node[state, minimum size=1.5cm] (y2) [right= of y1] {$\mathbf{y}_{2}$};
  \node[rectangle state, minimum size=1.5cm] (x12) [right= of x11] {$x_{12}$};
  \node[rectangle state, minimum size=1.5cm] (x22) [right= of x21] {$\mathbf{x}_{22}$};
  \node[rectangle state, minimum size=1.5cm] (x32) [right= of x31] {$\mathbf{x}_{32}$};
  \node[state, draw=none, minimum size=1.5cm] (ykdots) [right= of y2] {$\cdots$};
  \node[state, draw=none, minimum size=1.5cm] (x1kdots) [right= of x12] {$\cdots$};
  \node[state, draw=none, minimum size=1.5cm] (x2kdots) [right= of x22] {$\cdots$};
  \node[state, draw=none, minimum size=1.5cm] (x3kdots) [right= of x32] {$\cdots$};
  \node[state, minimum size=1.5cm] (ynm1) [right= of ykdots] {$\mathbf{y}_{n-1}$};
  \node[rectangle state, minimum size=1.5cm] (x1nm1) [below= of ynm1] {$x_{1,n-1}$};
  \node[rectangle state, minimum size=1.5cm] (x2nm1) [below= of x1nm1] {$\mathbf{x}_{2,n-1}$};
  \node[rectangle state, minimum size=1.5cm] (x3nm1) [below= of x2nm1] {$\mathbf{x}_{3,n-1}$};
  \node[state, minimum size=1.5cm] (yn) [right= of ynm1] {$\mathbf{y}_{n}$};
  \node[rectangle state, minimum size=1.5cm] (x1n) [below= of yn] {$x_{1n}$};
  \node[rectangle state, minimum size=1.5cm] (x2n) [below= of x1n] {$\mathbf{x}_{2n}$};
  \node[rectangle state, minimum size=1.5cm] (x3n) [below= of x2n] {$\mathbf{x}_{3n}$};
  \draw[->] 
    (x11) edge[left] (y1)
    (x21) edge[bend left] (y1)
    (x31) edge[bend left] (y1)
    (x12) edge[left] (y2)
    (x22) edge[bend left] (y2)
    (x32) edge[bend left] (y2)
    (x1nm1) edge[left] (ynm1)
    (x2nm1) edge[bend left] (ynm1)
    (x3nm1) edge[bend left] (ynm1)
    (x1n) edge[left] (yn)
    (x2n) edge[bend left] (yn)
    (x3n) edge[bend left] (yn)
    (x11) edge[left] (x12)
    (x21) edge[left] (x22)
    (x31) edge[left] (x32)
    (x12) edge[left] (x1kdots)
    (x22) edge[left] (x2kdots)
    (x32) edge[left] (x3kdots)
    (x1kdots) edge[left] (x1nm1)
    (x2kdots) edge[left] (x2nm1)
    (x3kdots) edge[left] (x3nm1)
    (x1nm1) edge[left] (x1n)
    (x2nm1) edge[left] (x2n)
    (x3nm1) edge[left] (x3n)
    ;
\end{tikzpicture}


\end{document}

and it looks fine:

correct image

However, when I drop that code in verbatim into a draft of a paper I'm writing, it looks like this:

bad picture

The alignment is wrong, the nodes don't have borders drawn anymore, etc. Anybody know what's going on? Do any of the following packages in my preamble mess up TikZ stuff? The successful compilation was performed on Rstudio, and the unsuccessful compilation took place on Texmaker. With the latter, I compile by pressing F1, which triggers "Quick Build" and the settings of that are displayed in the pictures at the bottom. I use XeLateX because I've had some problems in the past with images (pdf mostly) being displayed properly. The "XeLateX" command is given as xelatex -synctex=1 -interaction=nonstopmode %.tex.

\documentclass[12pt]{article}

\usepackage{amsmath, amsfonts, bm, mathtools, algpseudocode, amssymb}
\usepackage[dvips]{graphicx}
\usepackage{psfrag,epsf,algorithm}
\usepackage{enumerate}
\usepackage{natbib}
\usepackage{url} % not crucial - just used below for the URL

% tikz stuff
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows, shapes}


%\pdfminorversion=4
% NOTE: To produce blinded version, replace "0" with "1" below.
\newcommand{\blind}{0}

% for proofs!
\newenvironment{proof}{\paragraph{Proof:}}{\hfill$\square$}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel} 
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}

% DON'T change margins - should be 1 inch all around.
\addtolength{\oddsidemargin}{-.5in}%
\addtolength{\evensidemargin}{-.5in}%
\addtolength{\textwidth}{1in}%
\addtolength{\textheight}{1.3in}%
\addtolength{\topmargin}{-.8in}%


\begin{document}

Quick Build Settings

enter image description here

  • Welcome to TeX-SE! How do you compile your draft? That is, which compilation chain are you using? The fact that you are loading psfrag and epsf seems to indicate that you run latex, convert to ps and then to pdf. The details of this chain may be important for understanding what's going on. (And do you need psfrag and epsf in the year 2019?) – user121799 Jun 4 at 19:18
  • this is unrelated to texmaker (or rstudio) but rather to which tex system you used, latex or pdflatex and the versions of packages involved. – David Carlisle Jun 4 at 19:23
  • I suppose that you are viewing the dvi output, which doesn't really make sense. View the pdf output. – user187802 Jun 4 at 19:27
  • @marmot see edit. Regarding psfrag and epsf, those were just part of the journal's template they distribute. – Taylor Jun 4 at 19:59
  • You seem to be compiling with xelatex (which may not be optimal, but if the journal forces you, what can you do) but the second picture doesn't show which system commands your program associates with xelatex. Maybe you should really double check it runs xelatex. I always compile from the console so I can't say much. – user121799 Jun 4 at 20:17

Your Answer

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

Browse other questions tagged or ask your own question.