[Tex/LaTex] IEEE latex template. How to fit a figure with tikzpicture in one coulumn

ieeetrantikz-pgf

I'm using IEEE Conference Latex template. I want to have a figure with tikzpicture. My figure is not an image, is a box (rectangle) with some text inside of that. This is my code:

\begin{figure}[t]
\begin{tikzpicture}
\node [draw,rectangle,align=left,right=2pt] (mid) 
            {\textless bug\textgreater\\
            \textless \texttt{bug\_id}\textgreater 175229\textless \texttt{/bug\_id}\textgreater\\ 
           \textless \texttt{creation\_ts}\textgreater 2007-02-23 03:34:00 \textless\texttt{/creation\_ts}\textgreater\\ 
            \textless \texttt{short\_desc}\textgreater\\ 
                \hspace*{0.1in}
Should be able to open editor automatically when a task is activated\\ 
            \textless \texttt{/short\_desc}\textgreater\\ 
           \textless /bug\textgreater\\ 
          .......................................................................... };

\end{tikzpicture}
\captionsetup{justification=centering}
\caption{The overall structure of approach}
\end{figure}

Problem is that,at the end, the figure crosses the first column and it has an overlap with the second column. How I can fit it to just one column?

Best Answer

You can either scale the node by some factor by adding e.g.

 scale=0.9

as a parameter to the node or you can break the lines by hand.

Sample output

\documentclass[conference]{IEEEtran}

\usepackage{tikz,caption}

\usepackage{lipsum}

\begin{document}

\title{Sample document}

\author{\IEEEauthorblockN{A. Author}
\IEEEauthorblockA{Address\\City}}

\maketitle

\IEEEpeerreviewmaketitle

\section{Introduction}

\lipsum[1-2]

\begin{figure}[t]
\centering
\begin{tikzpicture}
\node [draw,rectangle,align=left,right=2pt,scale=0.8] (mid) 
            {\textless bug\textgreater\\
            \textless \texttt{bug\_id}\textgreater 175229\textless \texttt{/bug\_id}\textgreater\\ 
           \textless \texttt{creation\_ts}\textgreater 2007-02-23 03:34:00 \textless\texttt{/creation\_ts}\textgreater\\ 
            \textless \texttt{short\_desc}\textgreater\\ 
                \hspace*{0.1in}
Should be able to open editor automatically when a task is activated\\ 
            \textless \texttt{/short\_desc}\textgreater\\ 
           \textless /bug\textgreater\\ 
          .......................................................................... };

\end{tikzpicture}
\captionsetup{justification=centering}
\caption{The overall structure of approach}
\end{figure}

\begin{figure}[t]
\centering
\begin{tikzpicture}
\node [draw,rectangle,align=left,right=2pt] (mid) 
            {\textless bug\textgreater\\
            \textless \texttt{bug\_id}\textgreater 175229\textless \texttt{/bug\_id}\textgreater\\ 
           \textless \texttt{creation\_ts}\textgreater 2007-02-23 03:34:00 \\\textless\texttt{/creation\_ts}\textgreater\\ 
            \textless \texttt{short\_desc}\textgreater\\ 
                \hspace*{0.1in}
                Should be able to open editor automatically when a task\\
                \hspace*{0.1in}is activated\\ 
            \textless \texttt{/short\_desc}\textgreater\\ 
           \textless /bug\textgreater\\ 
          .......................................................................... };

\end{tikzpicture}
\captionsetup{justification=centering}
\caption{The overall structure of approach}
\end{figure}

\lipsum[2-4]
\end{document}

However, a more usual way to display material like this would be to use e.g. the listings package