0

I have a problem with fitting two flowcharts encased in frame boxes to fit nicely within a single page and how do you add a little more bottom space to the box frame?

\documentclass[11pt,twoside, a4paper]{report}
\usepackage{fontspec}
\setmainfont{Tex Gyre Schola}
\usepackage[margin=0.75in]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

%% tikz \tikzset{ block/.style = { rectangle, draw, text width=5em, text centered, minimum width=3cm, minimum height=1cm, rounded corners, }, line/.style = { draw, -latex', }, text/.style = {textwidth = 3em }, longblock/.style = { rectangle, draw, text width=10em, text centered, minimum width=3cm, minimum height=1cm, rounded corners, fill=white }, }

%% personal commands \newcommand{\mybox}[4]{ \begin{figure}[h] \centering \begin{tikzpicture} \node[anchor=text,text width=\columnwidth-1.2cm, draw, rounded corners, line width=0.5pt, fill=#3, inner sep=1mm] (big) {\#4}; \node[draw, rounded corners, line width=.5pt, fill=#2, anchor=west, xshift=5mm] (small) at (big.north west) {#1}; \end{tikzpicture} \end{figure} }

\begin{document} \mybox{QT nhân giống bằng nuôi cấy mô}{black!40}{black!10}{

\vspace{2ex}

\medskip \hspace{5.5ex} \begin{tikzpicture}[node distance = 1cm, auto] \node [longblock] (bl1) {Chọn vật liệu nuôi cấy}; \node [longblock, below of=bl1, node distance=1.75cm] (bl2) {Khử trùng}; \node [longblock, below of=bl2, node distance=1.75cm] (bl3) {Tạo chồi}; \node [longblock,below of=bl3, node distance=1.75cm] (bl4) {Tạo rễ}; \node [longblock, below of=bl4, node distance=1.75cm] (bl5) {Cấy cây vào môi trường thích ứng}; \node [longblock, below of=bl5, node distance=1.75cm] (bl6) {Trồng cây trong vườn ươm};

\path [line] (bl1) -- (bl2);
\path [line] (bl2) -- (bl3);
\path [line] (bl3) -- (bl4);
\path [line] (bl4) -- (bl5);
\path [line] (bl5) -- (bl6);

\end{tikzpicture}

}

\vspace{-65.75ex}

\begin{flushright} \mybox{Nhân giống bằng nuôi cấy mô ở cà rốt}{black!40}{black!10}{

\vspace{4ex}

\begin{tikzpicture} \hspace{7ex} \node [longblock] (bl1) {Lát cắt ngang củ cà rốt}; \node [longblock, below of=bl1, node distance=1.75cm] (bl2) {Các mẫu mô}; \node [longblock, below of=bl2, node distance=2cm] (bl3) {Các tế bào được tách rời trong môi trường nuôi cây}; \node [longblock,below of=bl3, node distance=2cm] (bl4) {Tế bào phân chia}; \node [longblock, below of=bl4, node distance=1.75cm] (bl5) {Mô sẹo}; \node [longblock, below of=bl5, node distance=1.75cm] (bl6) {Cây con sinh trưởng trong ống nghiệm}; \node [longblock, below of=bl6, node distance=1.75cm] (bl7) {Đem trồng để tạo cây trưởng thành};

\path [line] (bl1) -- (bl2);
\path [line] (bl2) -- (bl3);
\path [line] (bl3) -- (bl4);
\path [line] (bl4) -- node[anchor=east] {Nuôi cấy} (bl5);
\path [line] (bl5) -- node[anchor=east] {Nuôi cấy} node[anchor=west]{Hoocmôn sinh trưởng}(bl6);
\path [line] (bl6) -- (bl7);

\end{tikzpicture} } \end{flushright} \end{document}

Adrik Ivanov
  • 487
  • 2
  • 10

1 Answers1

0
  • I would put both images to one float with position options [p]. - Nesting tikz image in tikz image is not good idea, you can experiences unexpected problems (aligning of images)
  • Defining new commands for inserting images doesn't shorten code or make it more clear, I would rather insert image directly in float environment
  • Using additional tikz libraries can significant shorten code, make it more concise and clear:
\documentclass[11pt,twoside, a4paper]{report}
\usepackage{fontspec}
\setmainfont{Tex Gyre Schola}
\usepackage[margin=0.75in]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                backgrounds,
                chains,
                fit,
                positioning,
                quotes,
                shapes}

%---------------- Show page layout. Don't use in a real document! \usepackage{showframe} \renewcommand\ShowFrameLinethickness{0.15pt} \renewcommand*\ShowFrameColor{\color{red}} %---------------------------------------------------------------% \usepackage{lipsum}% For dummy text. Don't use in a real document

%% tikz \tikzset{FC/.style = { node distance = 7mm, start chain = going below, % base/.style = {draw, rounded corners, line width=0.5pt}, FIT/.style = {base, fill=gray!10, minimum width=\dimexpr\linewidth-1.2cm\relax, inner sep=4mm, xshift=\dimexpr0.5\linewidth-10em\relax, yshift=2mm, fit=##1}, T/.style = {base, fill=gray!30, anchor=west, xshift=5mm}, % line/.style = {draw, -Latex}, block/.style = {base, text width=5em, align=center}, longblock/.style = {base, fill=white, text width=10em, align=center, minimum height=1cm}, height=1cm}, every edge quotes/.append style = {font=\small} } }

\begin{document} \begin{figure}[p] \centering \begin{tikzpicture}[FC] \begin{scope}[nodes={longblock, on chain, join=by line}] \node (bl1) {Chọn vật liệu nuôi cấy}; \node (bl2) {Khử trùng}; \node (bl3) {Tạo chồi}; \node (bl4) {Tạo rễ}; \node (bl5) {Cấy cây vào môi trường thích ứng}; \node (bl6) {Trồng cây trong vườn ươm}; \end{scope} \scoped[on background layer] \node[FIT=(bl1) (bl6)] (big) {}; \node[T] (small) at (big.north west) {QT nhân giống bằng nuôi cấy mô}; \end{tikzpicture}

\medskip \begin{tikzpicture}[FC] \begin{scope}[nodes={longblock, on chain, join=by line}] \node (bl1) {Lát cắt ngang củ cà rốt}; \node (bl2) {Các mẫu mô}; \node (bl3) {Các tế bào được tách rời trong môi trường nuôi cây}; \node (bl4) {Tế bào phân chia}; \node (bl5) {Mô sẹo}; \node (bl6) {Cây con sinh trưởng trong ống nghiệm}; \node (bl7) {Đem trồng để tạo cây trưởng thành}; \end{scope} \scoped[on background layer] \node[FIT=(bl1) (bl7)] (big) {}; \node[T] (small) at (big.north west) {Nhân giống bằng nuôi cấy mô ở cà rốt}; % \path (bl4) edge["Nuôi cấy"] (bl5); \path (bl5) edge["Nuôi cấy" ', "Hoocmôn sinh trưởng"] (bl6); \end{tikzpicture} \end{figure} \end{document}

enter image description here

Addendum: For the flowchart asked in your comment:

  • please always put your ask in question, that it can be (better) visible to all site members
  • you can draw this flowchart on the same way as are drawn in above MWE, so its code can be:
    \begin{tikzpicture}[FC] 
    \begin{scope}[nodes={block, on chain, join=by line}]
\node (bl1) {Hạt giống SNC}; 
\node (bl2) {Hạt giống \\ NC}; 
\node (bl3) {Hạt giống XN}; 
    \end{scope}
\node [below right = of bl3] (bl4) {Sản xuất đại trà}; 
\path [line] (bl3) |- (bl4); 
    \end{tikzpicture}

however, your document preamble had to have the content of above MWE's preamble too.

enter image description here

Zarko
  • 296,517
  • @Anon, on the same way as is done in my answer. See addendum. – Zarko Dec 26 '21 at 12:36
  • What code do you use to make the light grey portion covering the flowchart smaller? – Adrik Ivanov Dec 28 '21 at 02:26
  • @Anon, all used code is in the answer. All modes size are the same as you defined in your MWE. Defined are as part of nodes styles collected in \tikzset. – Zarko Dec 28 '21 at 07:54