2

How can I locally define the local horizontal text alignment? In the example below I would like the word TITLE to be centered and the rest of the text with the usual justified (text distributed between the margins).

How can I move horizontally the flowcharts to the page center?

Thank you.

\documentclass[twoside,b5paper,12pt,fleqn]{psd_thesis}
\usepackage{amsmath,amssymb,amsfonts}           \usepackage[T1]{fontenc}
\usepackage{newtxmath,newtxtext}                

\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}

\begin{document}
% Define block styles
\tikzset{
block/.style={
rectangle,
draw,
text width=20em,
text centered,
rounded corners
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
}
}

\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center,     nodes={rectangle,draw, anchor=center} ]{
|[block]| {TITLE \\
text text text text text text text text text text text text text text text     text text text text text
}               &  \\
|[block]| {TITLE \\
text text text text text text text text text text text
}               &  \\                                              
|[block]| {TITLE \\
text text text text text text text text text text text text text text text     text 
}               &  \\                                              
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\end{tikzpicture}

\end{document}

enter image description here

The psd_thesis.cls is reported below:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{psd_thesis}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}

\ProcessOptions

\LoadClass{report}

\renewcommand{\baselinestretch}{1.5}  % Double-spaced

\usepackage[round]{natbib}  % bib style

%\usepackage[tx]{sfmath}      % a package of fonts
%\usepackage{helvet}             % For Helvetica (Arial is just a bad copy of Helvetica)
%\renewcommand\familydefault{\sfdefault}  

\renewcommand{\@makechapterhead}[1]{%
\vspace*{50\p@}%  {\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\large \scshape \bfseries \@chapapp\space \thechapter
\par\nobreak
\vskip 20\p@
\fi
\interlinepenalty\@M
\large \bfseries #1\par\nobreak
\vskip 40\p@  }}

\renewcommand{\@makeschapterhead}[1]{%
\vspace*{50\p@}%{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\large \scshape \bfseries  #1\par\nobreak
\vskip 40\p@  }}  

\renewcommand{\section}{\@startsection{section}% % the name{1}% % the level{0mm}% % the indent{3.0\baselineskip}% % the before skip{2.5\baselineskip}%    % the after skip{\normalfont \normalsize}} % the style

\renewcommand{\subsection}{\@startsection{subsection}% % the name
{2}% % the level{0mm}% % the indent{-\baselineskip}% % the before  skip{1.5\baselineskip}% % the after skip{\normalfont \normalsize}} % the style

\endinput
  • \begin{center}\begin{tikzpicture}...\end{tikzpicture}\end{center}? – Torbjørn T. Jul 8 '16 at 10:56
  • @Torbjørn T. I already tried it but no change – Luca Jul 8 '16 at 11:15
1

Another solution, without use of matrix library ...

In such simple case as is your flowchart, the use TikZ library chains is very effective way (to my opinion, the best) to draw flowcharts:

\documentclass[twoside,b5paper,12pt,fleqn]{book}
\usepackage[T1]{fontenc}
\usepackage{newtxmath,newtxtext}
\usepackage{tikz}
\usetikzlibrary{arrows,chains}

\usepackage{showframe}

\begin{document}

\centering
    \begin{tikzpicture}[
    node distance = 5mm,
      start chain = A going below,
block/.style={rectangle, draw, rounded corners,
              text width=20em, align=justify,
              on chain=A, join=by -latex
              },
                        ]
\node[block]    {\hfil  TITLE TITLE TITLE TITLE\\% this works for one line title
                 text text text text text text text text text text text text text text text     
                 text text text text text};
\node[block]    {\parbox{\linewidth}{\centering
                        MULTILINE TITLE MULTILINE TITLE MULTILINE TITLE 
                        }\\[1.5ex]                    % in case of multi line title
                 text text text text text text text text text text text text};
\node[block]    {\hfil  TITLE \\
                 text text text text text text text text text text text text text text text     
                 text};
    \end{tikzpicture}
\end{document}

Added package showframe serves only to show page layout and that you can see, that flowchart is centered in text field. In formatting of text in nodes I understand, that text in it should be justified (as is other text in document), only title should be centered. I show two ways, how to center only a "title" of node: if it is in single line or if it is multi lined.

Addendum: For add a caption, you need to put flowchart into figure environment (preambe is the same as above):

\begin{document}
    \begin{figure}
    \centering
    \begin{tikzpicture}[
node distance = 5mm,
  start chain = A going below,
 block/.style = {rectangle, draw, rounded corners,
                 text width=20em, align=justify,
                 on chain=A, join=by -latex
                },
                        ]
\node[block]    {\hfil  TITLE TITLE TITLE TITLE\\% this works for one line title
                 text text text text text text text text text text text text text text text
                 text text text text text};
\node[block]    {\parbox{\linewidth}{\centering
                        MULTILINE TITLE MULTILINE TITLE MULTILINE TITLE
                        }\\[1.5ex]                    % in case of multi line title
                 text text text text text text text text text text text text};
\node[block]    {\hfil  TITLE \\
                 text text text text text text text text text text text text text text text
                 text};
    \end{tikzpicture}
\caption{my extremly important flowchart \dots}
\label{fig:flowchart}
    \end{figure}
\end{document}

enter image description here

  • Is there a way to add a caption to the flowchart? – Luca Jul 8 '16 at 14:24
  • yes, you need to put it in figure environment. See update of mine answer. – Zarko Jul 8 '16 at 14:34
0

The center environment should do, but a problem is that you have added a second column (with empty nodes) to your matrix, and because of column sep=2cm there is a lot of extra whitespace in the tikzpicture. See below where I added draw to the options of the matrix, and the showframe package to draw a box around the text area.

In the second tikzpicture I removed all the & from the matrix. The outer frame in the image shows the text area.

enter image description here

\documentclass[twoside,b5paper,12pt,fleqn]{psd_thesis}
\usepackage{showframe} % to show text area
\usepackage{amsmath,amssymb,amsfonts}
\usepackage[T1]{fontenc}
\usepackage{newtxmath,newtxtext}                

\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}
% Define block styles
\tikzset{
block/.style={
rectangle,
draw,
text width=20em,
text centered,
rounded corners
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
}
}

\begin{document}

\begin{center}
\begin{tikzpicture}
\matrix (m)[draw,matrix of nodes, column  sep=2cm,row  sep=8mm, align=center,     nodes={rectangle,draw, anchor=center} ]{
|[block]| {TITLE \\
text text text text text text text text text text text text text text text     text text text text text
}               &  \\
|[block]| {TITLE \\
text text text text text text text text text text text
}               &  \\                                              
|[block]| {TITLE \\
text text text text text text text text text text text text text text text     text 
}               &  \\                                              
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\end{tikzpicture}


\begin{tikzpicture}
\matrix (m)[draw,matrix of nodes, column  sep=2cm,row  sep=8mm, align=center,     nodes={rectangle,draw, anchor=center} ]{
|[block]| {TITLE \\
text text text text text text text text text text text text text text text     text text text text text
}                 \\
|[block]| {TITLE \\
text text text text text text text text text text text
}                 \\                                              
|[block]| {TITLE \\
text text text text text text text text text text text text text text text     text 
}                 \\                                              
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\end{tikzpicture}
\end{center}
\end{document}
  • T.I solved the problem of the flowchart alignment adding \begine{center} and end{center} and deleting the "&". Still remains to align the "text..." with justified alignment. Thank you. – Luca Jul 8 '16 at 11:34
  • @Luca Set text width=\textwidth in the block style? – Torbjørn T. Jul 8 '16 at 12:27

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.