2

I've made a tree diagram using the forest package. To prevent the diagram stretching beyond the page I've placed it in a box. How can I place this box within the text such that Latex can determine its location within the final document in a way that text continues smoothly on either side? With figures, tables etc I have had used [h!] as a parameter to achieve this effect. But I'm not sure how to replicate this here.

\documentclass[12pt]{article}\usepackage{fullpage}
\renewcommand{\baselinestretch}{1.5}

\usepackage[linguistics]{forest}
\begin{document}
The following tree-diagram illustrates blah... \makebox[15ex][r]{
\begin{forest}
[$ \omega $
[Physical
]
[Mental 
]
]
\end{forest} } The idea is that a distinct structure blah....
\end{document}
3

[New answer after comments]

There are several ways to consider the placement of an object in a text reflow system. Primarily TeX has the concept of floats. That is an object can nominate zonal areas where text may flow around the object and it seems that is what you are requesting here (The smooth flow of text around an inline floating object) Such an example is shown in the lower part of this example page. enter image description here The position of where the float may move to is discussed here
How to influence the position of float environments like figure and table in LaTeX?

The alternative to an inline float is finishing the text in a fixed location which will generally result in a ragged finish to the previous paragraph, see upper example. There are possibilities to fix the object at a nominal position and flow the text before and after (or optionally wrap text on one or two sides) for single side the wrapfig package is fairly good. However for two sided say midway in a doublecolumn it can be problematic see the older answer after this mwe.

\documentclass[12pt]{article}
\usepackage{fullpage}

\usepackage{blindtext,letltxmacro,xcolor,xparse,lipsum}% for demo only [start]
\LetLtxMacro{\blindtextblindtext}{\blindtext}
\LetLtxMacro{\blindtextBlindtext}{\Blindtext}
\RenewDocumentCommand{\blindtext}{O{\value{blindtext}}}{%
  \begingroup\color{gray}\textit{\blindtextblindtext[#1]}\endgroup
}

\usepackage{showframe}% for demo only [end]

\usepackage[linguistics]{forest}

\renewcommand{\baselinestretch}{1.15} %modified for ilustration

\begin{document}
\blindtext[1] \textbf{Here we see (or don't as the case may be) The following tree-diagram illustrates blah... [fixed ending]}\begin{center}[float is n/a]\newline\begin{forest}[(Fixed here by a centre environment)\\$ \omega $[Physical][Mental]]\end{forest}\end{center}\textbf{The idea is that a distinct structure blah.1...}%
\blindtext[1] \textbf{Here we see (or dont as the case may be) The following tree-diagram illustrates there is not enough room blah... .[floating]}\begin{figure}[bh]\centering\begin{forest}[(Float here as a figure environment)\\$ \omega $[Physical][Mental]]\end{forest}%
% replace this comment but KEEP one blank line

We can add some floating comment
\end{figure}
The idea is that a distinct structure blah.2...\blindtext[1] 

\lipsum[3]
\end{document}

[OLD answer with fragile cutwin]

This is very fragile especially combined with the 1.5 baselinestretch you specified (it works better if that is the default of 1. An adjustment is possibly needed to the cutwin package for recalculating odd baseline values. NOTE that cutwin prefers the lines to be specified exactly to suite the number of the lines it is inserted within.

"How can I place this box within the text such that Latex can determine its location within the final document in a way that text continues smoothly on either side?"

enter image description here

\documentclass[12pt]{article}
\usepackage{fullpage}

\usepackage{cutwin}
\usepackage[most]{tcolorbox}

\usepackage{lipsum}% for demo only

\usepackage[linguistics]{forest}

\renewcommand{\baselinestretch}{1.5}

\begin{document}

\def\windowpagestuff{\centering \begin{minipage}{0.85\textwidth}
\begin{tcolorbox}[fit basedim=50pt]\centering\begin{forest}[$ \omega $[Physical][Mental]]\end{forest}\end{tcolorbox}~%
\end{minipage}}

\begin{cutout}{2}{0.33\textwidth}{0.33\textwidth}{6} % {lines above}{space to left}{space to right}{lines high}
\noindent The following tree-diagram illustrates that both Physical and Mental attributes are a result of $\omega$ ...The idea is that a distinct structure is achieved by trial and errors....\lipsum[66]
\end{cutout}
\lipsum[66]

\end{document}
  • I think this might do it, I was envisaging that the text would not wrap either side, but just above and below as it were. I should have made that clearer. – Marmitrob Jun 8 at 15:39
  • Would it be possible to do this without using a colored box? Ideally I would like to use an unbordered box without any fill color. – Marmitrob Jun 8 at 15:39
  • I tried this solution. Unfortunately, it was a little too fragile for me, and generated overlaid lines of text when put in the larger documents. Really appreciate your input though! – Marmitrob Jun 8 at 18:23
  • Sorry I'm having so much trouble expressing myself. What I was hoping was to place the tree diagram in the middle of some text, with the text not wrapped around it, but continuing seamlessly above and below. Ideally I want to do this so that Latex will set the diagram where ever it is most appropriate without having to worry about whether there is sufficient space on the bottom of the page etc. I used \makebox in the first place only to try to stop the diagram running over the edge of the page – Marmitrob Jun 9 at 0:46

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.