I am new to Tex and this question maybe is not written well, so I will try to explain it better.
I am writing a reference manual where there are a lot of "blocks" that all have the same structure: a piece of text (maybe one or two short paragraphs) and then an image (tipically a screenshot).
I would like to be able to define such a block in a way that, when exporting document to PDF, the output is on the same page. I understand that there will be some pages half-filled when this "block" begins and does not fit into the current page. In these cases, I expect the block to be placed entirely at the next page.
I have been playing with \begin{samepage}
, \begin{minipage}
and things like that (searching a lot in this same web) with no luck. Obviously I am doing something wrong, or taking a bad approach to solve the problem.
Take a look at my code:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Phasellus leo ipsum, dictum non auctor quis, euismod vitae enim. Mauris varius.
\begin{figure}[h]
\begin{center} \includegraphics[scale={0.7}]{IMG1} \end{center}
\caption{Image caption}
\label{fig:IMG1}
\end{figure}
I would like all this piece of text (2 paragraphs) and one figure to be always in the same page.
Can this be achieved? In fact I thought I got it when I discovered \begin{minipage}
! If this is the case, can you please write down a short code showing how to use it? (remember I am a newbie and some obvious things are not so obvious for me right now).
Edit: I will try @Werner tip, but I am already using a \newcommand to short all the previously written \begin{figure} environment. As this:
\newcommand{\figureSF}[4]{
\begin{figure}[h]
\begin{center} \includegraphics[scale={#4}]{#1} \end{center}
\caption{#2}
\label{#3}
\end{figure}
}
So the previous piece of code turns into:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Phasellus leo ipsum, dictum non auctor quis, euismod vitae enim. Mauris varius.
\figureSF{IMG1}{Image caption}{fig:IMG1}{0.7}
As this new command accept only 4 parameters, is there an easy way to modify it to handle the situation you are describing?