I'm completely new to Tikz...
I draw the following tikzpicture thanks to exemple found on the internet:
The code for Beamer class here:
\documentclass[aspectratio=169,compress,8pt,svgnames,dvipsnames]{beamer}
\usetheme{Warsaw}
\usecolortheme{seahorse}
\useoutertheme[footline=authortitle,subsection=true]{miniframes}
\usepackage{tikz}
\usetikzlibrary{mindmap,shapes,arrows,calc,arrows.meta}
\usepackage{verbatim}
\usepackage{bondgraphs}
% Define a few tikz styles and constants
% Theme Color
\colorlet{subsystemPartBgColor}{blue}%
\colorlet{subsystemPartFgColor}{red}%
\colorlet{subsystemPartBorderColor}{green}%
\colorlet{subsystemBgColor}{yellow}%
\colorlet{subsystemFgColor}{black}%
\colorlet{subsystemBorderColor}{black!50}%
% Block
\newcommand*{\subssytemFontStyle}[1]{\textbf{#1}}% Text Font Style For Subsystem
\tikzstyle{subsystemStyle} = [text=subsystemFgColor, font=\bfseries]%
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em]%
\tikzstyle{SubSysPart} = [sensor, text width=6em, fill=subsystemPartBgColor,minimum height=8em, rounded corners, text=subsystemPartFgColor, draw=subsystemPartBorderColor]% Part of a subsystem
% Arrow
% !!! Needs \usetikzlibrary{arrows.meta}
\tikzstyle{ann} = [above, text width=6em]% Arrow for Phisical Quantity wich are not Flows or Effort in Bond Graph
\tikzstyle{signal_num} = [-latex, color=red!30!black]% For signal numeric Arrows
\tikzstyle{signal_ana} = [-{Latex[open]}]% For signal analog Arrows
\tikzstyle{env} = [-{Stealth[open]}]% For environement Arrows
\tikzstyle{Pf_out} = [bond, f_out]% For f_out Bond Arrow
\tikzstyle{Pe_out} = [bond, e_out]% For e_out Bond Arrow
\tikzstyle{Pf_in} = [bond, f_in]% For f_in Bond Arrow
\tikzstyle{Pe_in} = [bond, e_in]% For e_in Bond Arrow
\tikzstyle{var} = [->]% For Variable Bond Arrow
\tikzstyle{miss} = [-{Implies},double]% For Mission Bond Arrow
\begin{document}
\begin{frame}[allowframebreaks]
\begin{figure}[h]
% We need layers to draw the block diagram
\pgfdeclarelayer{background}%
\pgfdeclarelayer{foreground}%
\pgfsetlayers{background,main,foreground}%
%
% Define constants
\def\blockdist{3.2}%
\def\envdist{1.7}%
\def\comdist{1.2}%
\def\edgedist{2}%
\def\inletdist{2}%
%
\begin{tikzpicture}%
%# Subsystem part Node Block
%## Compressor Performance Model Block
\node (throttle) [SubSysPart] {Throttle};%
%## Compressor Inertia Block
% Note the use of \path instead of \node at ... below.
\path (throttle.west)+(-\blockdist,0) node (manifil) [SubSysPart] {manifold Filling};%
%## Command and Environement Block (invisible block, just for arrows)
\path (manifil.west)+(-\inletdist,0) node (inlet) [minimum height=8em] {};%
%## Susystem Background Block
\path [subsystemStyle] (throttle.south west)+(-2.3,-0.5) node (CPSs) {\subssytemFontStyle{supply manifold Subsystem}};%
% Now it's time to draw the colored rectangles.
% To draw them behind the blocks we use pgf layers. This way we
% can use the above block coordinates to place the backgrounds
\begin{pgfonlayer}{background}%
% Compute a few helper coordinates
\path (manifil.west |- throttle.north)+(-0.3,0.2) node (a) {};%
\path (CPSs.south -| throttle.east)+(+0.3,-0.2) node (b) {};%
\path[fill=subsystemBgColor,rounded corners, draw=subsystemBorderColor, dashed]
(a) rectangle (b);%
\path (manifil.north west)+(-0.2,0.2) node (a) {};%
\end{pgfonlayer}%
%# Arrows
% Unfortunately we cant use the convenient \path (fromnode) -- (tonode)
% syntax here. This is because TikZ draws the path from the node centers
% and clip the path at the node boundaries. We want horizontal lines, but
% the sensor and throttle blocks aren't aligned horizontally. instead we use
% the line intersection syntax |- to calculate the correct coordinate
%## Variable Arrows
\path [draw, var] ( $ (manifil.south east)!0.3!(manifil.east) $ ) -- node [above] {psmin$=$psmout} ( $ (throttle.south west)!0.3!(throttle.west) $ ) ;%
\path [draw, var] (manifil.east) -- node [above] {Tsmin$=$Tsmout} (throttle.west) ;%
\draw [var] ( $ (inlet.south east)!0.5!(inlet.east) $ ) -- node [above,near start] {Tsmin$=$Tcpout} ( $ (manifil.south west)!0.5!(manifil.west) $ ) ;%
%### Outlet
%## Power Arrows
%### Inlet
\draw [Pf_in] ( $ (inlet.north east)!0.5!(inlet.east) $ ) -- node [above,near start] {Qsmin$=$Qcp} ( $ (manifil.north west)!0.5!(manifil.west) $ ) ;%
\draw [Pe_out] (inlet.east) -- node [above,near start] {psmin$=$pcpout} (manifil.west) ;%
%### Outlet
\draw [Pf_out] ( $ (manifil.north east)!0.3!(manifil.east) $ ) -- node [above] {Qsmout} ( $ (throttle.north west)!0.3!(throttle.west) $ ) ;%
% We could simply have written (manifil) .. (throttle.140). However, it's
% best to avoid hard coding coordinates
\draw [Pf_out] ( $ (throttle.north east)!0.60!(throttle.east) $ ) -- node [ann, pos=0.61] {Mass Flow Rate} + (\edgedist,0)
node[right] {Qsmout};%
\draw [Pf_out] ( $ (throttle.south east)!0.40!(throttle.east) $ ) -- node [ann, pos=0.61] {Fuel Cell Pressure} + (\edgedist,0)
node[right] {psmout$=p_{fc,in}$};%
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
I set all the "constants" to have good positioning, no overlaping, etc.
But when I tried to use this figure in an Article DocumentClass I got this (text overlapings circled in red):
Here the code:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{mindmap,shapes,arrows,calc,arrows.meta}
\usepackage{verbatim}
\usepackage{bondgraphs}
% Define a few tikz styles and constants
% Theme Color
\colorlet{subsystemPartBgColor}{blue}%
\colorlet{subsystemPartFgColor}{red}%
\colorlet{subsystemPartBorderColor}{green}%
\colorlet{subsystemBgColor}{yellow}%
\colorlet{subsystemFgColor}{black}%
\colorlet{subsystemBorderColor}{black!50}%
% Block
\newcommand*{\subssytemFontStyle}[1]{\textbf{#1}}% Text Font Style For Subsystem
\tikzstyle{subsystemStyle} = [text=subsystemFgColor, font=\bfseries]%
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em]%
\tikzstyle{SubSysPart} = [sensor, text width=6em, fill=subsystemPartBgColor,minimum height=8em, rounded corners, text=subsystemPartFgColor, draw=subsystemPartBorderColor]% Part of a subsystem
% Arrow
% !!! Needs \usetikzlibrary{arrows.meta}
\tikzstyle{ann} = [above, text width=6em]% Arrow for Phisical Quantity wich are not Flows or Effort in Bond Graph
\tikzstyle{signal_num} = [-latex, color=red!30!black]% For signal numeric Arrows
\tikzstyle{signal_ana} = [-{Latex[open]}]% For signal analog Arrows
\tikzstyle{env} = [-{Stealth[open]}]% For environement Arrows
\tikzstyle{Pf_out} = [bond, f_out]% For f_out Bond Arrow
\tikzstyle{Pe_out} = [bond, e_out]% For e_out Bond Arrow
\tikzstyle{Pf_in} = [bond, f_in]% For f_in Bond Arrow
\tikzstyle{Pe_in} = [bond, e_in]% For e_in Bond Arrow
\tikzstyle{var} = [->]% For Variable Bond Arrow
\tikzstyle{miss} = [-{Implies},double]% For Mission Bond Arrow
\begin{document}
%\begin{frame}[allowframebreaks]
\begin{figure}[h]
% We need layers to draw the block diagram
\pgfdeclarelayer{background}%
\pgfdeclarelayer{foreground}%
\pgfsetlayers{background,main,foreground}%
%
% Define constants
\def\blockdist{3.2}%
\def\envdist{1.7}%
\def\comdist{1.2}%
\def\edgedist{2}%
\def\inletdist{2}%
%
\begin{tikzpicture}%
%# Subsystem part Node Block
%## Compressor Performance Model Block
\node (throttle) [SubSysPart] {Throttle};%
%## Compressor Inertia Block
% Note the use of \path instead of \node at ... below.
\path (throttle.west)+(-\blockdist,0) node (manifil) [SubSysPart] {manifold Filling};%
%## Command and Environement Block (invisible block, just for arrows)
\path (manifil.west)+(-\inletdist,0) node (inlet) [minimum height=8em] {};%
%## Susystem Background Block
\path [subsystemStyle] (throttle.south west)+(-2.3,-0.5) node (CPSs) {\subssytemFontStyle{supply manifold Subsystem}};%
% Now it's time to draw the colored rectangles.
% To draw them behind the blocks we use pgf layers. This way we
% can use the above block coordinates to place the backgrounds
\begin{pgfonlayer}{background}%
% Compute a few helper coordinates
\path (manifil.west |- throttle.north)+(-0.3,0.2) node (a) {};%
\path (CPSs.south -| throttle.east)+(+0.3,-0.2) node (b) {};%
\path[fill=subsystemBgColor,rounded corners, draw=subsystemBorderColor, dashed]
(a) rectangle (b);%
\path (manifil.north west)+(-0.2,0.2) node (a) {};%
\end{pgfonlayer}%
%# Arrows
% Unfortunately we cant use the convenient \path (fromnode) -- (tonode)
% syntax here. This is because TikZ draws the path from the node centers
% and clip the path at the node boundaries. We want horizontal lines, but
% the sensor and throttle blocks aren't aligned horizontally. instead we use
% the line intersection syntax |- to calculate the correct coordinate
%## Variable Arrows
\path [draw, var] ( $ (manifil.south east)!0.3!(manifil.east) $ ) -- node [above] {psmin$=$psmout} ( $ (throttle.south west)!0.3!(throttle.west) $ ) ;%
\path [draw, var] (manifil.east) -- node [above] {Tsmin$=$Tsmout} (throttle.west) ;%
\draw [var] ( $ (inlet.south east)!0.5!(inlet.east) $ ) -- node [above,near start] {Tsmin$=$Tcpout} ( $ (manifil.south west)!0.5!(manifil.west) $ ) ;%
%### Outlet
%## Power Arrows
%### Inlet
\draw [Pf_in] ( $ (inlet.north east)!0.5!(inlet.east) $ ) -- node [above,near start] {Qsmin$=$Qcp} ( $ (manifil.north west)!0.5!(manifil.west) $ ) ;%
\draw [Pe_out] (inlet.east) -- node [above,near start] {psmin$=$pcpout} (manifil.west) ;%
%### Outlet
\draw [Pf_out] ( $ (manifil.north east)!0.3!(manifil.east) $ ) -- node [above] {Qsmout} ( $ (throttle.north west)!0.3!(throttle.west) $ ) ;%
% We could simply have written (manifil) .. (throttle.140). However, it's
% best to avoid hard coding coordinates
\draw [Pf_out] ( $ (throttle.north east)!0.60!(throttle.east) $ ) -- node [ann, pos=0.61] {Mass Flow Rate} + (\edgedist,0)
node[right] {Qsmout};%
\draw [Pf_out] ( $ (throttle.south east)!0.40!(throttle.east) $ ) -- node [ann, pos=0.61] {Fuel Cell Pressure} + (\edgedist,0)
node[right] {psmout$=p_{fc,in}$};%
\end{tikzpicture}
\end{figure}
\end{document}
So, the question is, what can I do to obtain a figure which will be automaticly adapt to the page size? Can I declare my "distance constants" (node distance, edge distance, text arrow pos, etc.) relatively compare to \textwidth for exemple?
EDIT 01/28/22: Answers below solve my picture problem. However I'm still wonder what are the "good practice" in matter of distance in a tikzpicture (absolute or relative). Wouldn't it be more rigorous if the distances were all given in terms of a distance like \textwidth
or something? If nobody respond to this in the coming days I will accept one answer and so "close" this question. One day I may ask a question just about "good practice" regarding distances with a Tikzpicture, but currently I'm not sure this question makes sense (I'm new to Tikz)...
standalone
class and include in your document with\includegraphics[width=\linewidth]{...}
.