Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have following trouble in LaTeX and I need some help. I am preparing a document which has this TeX code:

\documentclass [12pt]{article}
\usepackage{graphicx}
\usepackage[usenames,dvipsnames]{color}
\usepackage{needspace} % got it from http://www.tex.ac.uk/CTAN/macros/latex/contrib/needspace/
\usepackage{wrapfig}
\usepackage[a4paper, margin = 1cm, left = 2cm, right = 2cm, top = 1cm, bottom = 1.5cm, landscape, ignorehead] {geometry} 
\newcommand{\warrningheading}[1] { %
  \needspace{5\baselineskip}\colorbox{Black}{\parbox{\columnwidth}{\color{White}\textbf{#1}}}\nopagebreak[0]\vspace{2px} %
}
\newcommand{\warrningtext}[1] { %
  {\vspace{2px}{\textbf{#1}}\vspace{2px}} %
}
\newcommand{\wrapright}[1]{ %
  \begin{wrapfigure}{r}{0.31\linewidth} %
    \raggedleft\includegraphics{#1} %
  \end{wrapfigure}
}
\begin{document}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
\wrapright{pic1}
\warrningheading{WARRNING}
\warrningtext{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor
sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor
sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor
sit amet. Lorem ipsum dolor sit amet.}
\warrningheading{ATTENTION}
\warrningtext{Lorem ipsum dolor sit amet.}
\wrapright{pic3}
\warrningheading{POSSIBLY}
\warrningtext{LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM
IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET.
LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT
AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR
SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM
DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM
IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET.
LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT
AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR
SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM
DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM
IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET.
LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT AMET. LOREM IPSUM DOLOR SIT
AMET. }
\warrningheading{WARRNING}
\warrningtext{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor
sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor
sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor
sit amet. Lorem ipsum dolor sit amet.}
\warrningheading{ATTENTION}
\end{document}

And this gives mi the following PDF: enter image description here

but I want to make it like this: enter image description here

I have tried to use manny solutions, which works, but when I include pictures in document you can't get satisfactory result. The pictures are moving the text on the left "down" so you can't get text and picture in the same area. A picture reacts like it was a char, so on the left part there is one line of text and the text below is pushed down.

How to make a picture to be like the frame in word editors, and the text flows around it and not to move down?

I have tried the columns packages wich give me some success, and I have tried packages where you get vertical alignment (like parralel package) whic gives me more success, but with figures I have no luck.

The heading (black background) should be to the right margin except where there is a picture. Then it should be shorter, and not cover the picture

Can someone give me any solutions/hints/advices?

share|improve this question
    
Replace \columnwidth by \linewidth at definition of \warrninghead. –  Schweinebacke Nov 7 '11 at 14:36
    
Also, eliminate the spaces before the % in the \newcommand definitions. –  Peter Grill Nov 7 '11 at 15:29
add comment

2 Answers

The linegoal package provides the command \linegoal and calculates the remaining space of the line. I used it in your command \warningheading

screenshot

Note that it does matter in which order you specify wrapfigure and the text to surround it.

In the code you provided, I found that the images went outside of their designated space- I changed the \includegraphics statement to

\includegraphics[width=0.25\textwidth]{#1}

so that it matched the size of the wrapfigure

\documentclass [12pt]{article}
\usepackage[showframe=true,a4paper, margin = 1cm, left = 2cm, right = 2cm, top = 1cm, bottom = 1.5cm, landscape, ignorehead] {geometry} 
\usepackage{graphicx}
\usepackage[usenames,dvipsnames]{color}
\usepackage{needspace} % got it from http://www.tex.ac.uk/CTAN/macros/latex/contrib/needspace/
\usepackage{wrapfig}
\usepackage{linegoal} % newly loaded
\usepackage{lipsum}   % newly loaded

\newcommand{\warrningheading}[1] { %
  \needspace{5\baselineskip}\colorbox{Black}{\parbox{\linegoal}{\color{White}\textbf{#1}}}\nopagebreak[0]\vspace{2px} %
}

\newcommand{\warrningtext}[1] { %
  {\vspace{2px}{\textbf{#1}}\vspace{2px}} %
}

\newcommand{\wrapright}[1]{ %
  \begin{wrapfigure}{r}{0.25\textwidth} 
    \includegraphics[width=0.25\textwidth]{#1} 
  \end{wrapfigure}
}

\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\begin{document}

\wrapright{tiger1}
\warrningheading{WARNING}
\warrningtext{\lipsum[1]}

\warrningheading{ATTENTION}
\warrningtext{\lipsum[2]}

\end{document}
share|improve this answer
add comment

Update: 2011-11-15

Here is a solution using a minipage for each portion. This better matches the figure you provided as the desired output. The earlier solution below better matched your MWE (which used wrapfigure).

This version provides a single command that requires the two text portions, and accepts up to 4 images to be included. This can easily be expanded to be able to handle more if desired. For the case where there are no figures you just use:

\WarningBlock{<heading text>}{<main text>}

When there are figures you specify the percent of the line you want to be used by the figures, and each of the figures to be included. Since these are optional parameters they are to be specified within [] braces.

\WarningBlock[<size>][<pic1>][<pic2>][<pic3>][<pic4>]{<heading text>}{<main text>}

If there are no figures we use the full \linewidth. Otherwise we adjust the width of the text area based on the specified [<size>] parameter, adjusting for the separation parameters. Two settings that you might want to adjust are \MinipageHSep, which controls the horizontal separation between the text area and the figure area, and \MinipageVSep which controls the vertical separation between figures.

enter image description here

\documentclass[12pt]{article}
\usepackage[demo]{graphicx}% remove [demo] for real document
\usepackage[usenames,dvipsnames]{color}
\usepackage{calc}
\usepackage{lipsum}
\usepackage{needspace}
\usepackage{wrapfig}
\usepackage[a4paper, margin=1cm, left=2cm, right=2cm, top=1cm, bottom=1.5cm, landscape, ignorehead, showframe=true] {geometry}

\usepackage{xparse}% For optional args

% Adjust these two as desired to control the horizontal separation between
% the text and figures, and the vertical separation between the figures
\newlength{\MinipageHSep}\setlength{\MinipageHSep}{5pt}%
\newlength{\MinipageVSep}\setlength{\MinipageVSep}{4pt}%


\newcommand{\justWarningHead}[1]{%
    \colorbox{Black}{% 6pt below to adjust for \colorbox flowing into margin
    \parbox{\linewidth-6pt}{\color{White}\textbf{#1}}}%
    \par\vspace{2px}%
}

\newlength{\TextWidthSize}%
\newcommand{\InsertGraphic}[1]{\begin{minipage}{\linewidth}\includegraphics[width=\linewidth]{#1}\end{minipage}}%

\NewDocumentCommand{\WarningBlock}{o o o o o m m}{% up to 4 figures: #2, #3, #4, #5
    \IfNoValueTF{#2}{% no figures so use full width
        \setlength{\TextWidthSize}{\linewidth}%
    }{% figures specified, so need to shrink the text area
        \setlength{\TextWidthSize}{\linewidth-#1\linewidth-\MinipageHSep}%
    }%
    \begin{minipage}[t]{\TextWidthSize}% Minipage for the two text blocks
        \vspace{0pt}%
        \justWarningHead{#6}%
        \warningtext{#7}%
    \end{minipage}
    %
    \IfNoValueTF{#2}{}{% insert the figures, if any
        \hspace{\MinipageHSep}% add horizontal separation
        \begin{minipage}[t]{#1\linewidth}% Minipage for the figures
            \vspace{0pt}\InsertGraphic{#2}% Align the figures at the top
            \IfNoValueTF{#3}{}{\vfil\vspace{\MinipageVSep}\InsertGraphic{#3}}%
            \IfNoValueTF{#4}{}{\vfil\vspace{\MinipageVSep}\InsertGraphic{#4}}%
            \IfNoValueTF{#5}{}{\vfil\vspace{\MinipageVSep}\InsertGraphic{#5}}%
        \end{minipage}%
    }%
}%
\makeatother

\newcommand{\warningtext}[1]{%
  {{\textbf{#1}}\vspace{2px}}% removed leading \vspace here
}

\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\begin{document}
\color{red}
\WarningBlock[0.31][pic1]{WARNING - with one image}{\lipsum[1]}

\color{black}
\WarningBlock{WARNING - with no images}{\lipsum[2]}

\color{blue}
\WarningBlock[0.31][pic3][pic4]{WARNING - with 2 images}{\lipsum[1-2]}

\color{green}
\WarningBlock[0.31][pic5][pic6][pic7]{WARNING - with 3 images}{\lipsum[1-3]}

\color{black}
\WarningBlock[0.31][pic8][pic9][pic10][pic11]{WARNING - with 4 images}{\lipsum[1-2]}

\color{red}
\WarningBlock{WARNING - with no pictures}{\lipsum[4]}

\color{blue}
\WarningBlock[0.31][pic1]{WARNING - with one picture}{\lipsum[1]}

\color{black}
\WarningBlock[0.15][pic8][pic9][pic10][pic11]{WARNING - with 4 images}{\lipsum[1-3]}
\end{document}

Earlier Solution:

Here is something that should get you started. The colors are only used to be able to easily match the image with the corresponding portion of the code.

enter image description here

It's not perfect so you'll need to do some additional work. Some of the possible problems are:

  1. The code below allows only 0-4 figures. You'll need to adjust this if you want more, but should be pretty straightforward.

    The new macro \WarningHeading accepts up to 5 optional parameters to specify the figures to be included. If a figure is included, the first arg is the portion of the \linewidth that is to be used for the figure, and then you can specify up to 4 figures. Page 6 shows a different size for the figure width.

  2. The \colorbox in the header adds additional space above the text. So, assuming you want the top of the image aligned with the top of the horizontal box, I added \setlength{\intextsep}{-4pt} to adjust this. However, this is not applied at the top of the first page. So you'll notice that the top of the images are aligned with the top of the text, except for the first page.

    So, if you are ok with the top of the image aligned with the top of the text, remove the \setlength{\intextsep}{-4pt}. Otherwise, see the follow up question on this issue: Apply \intextsep at top of page.

  3. If the text is not long enough to extend past the figures, the following section will be indented. Not sure if this is problem or not. This problem can be seen at the beginning of Page 5. Since the text on Page 4 was not long enough, the beginning of the following section shows some indentation.

  4. You did not specify if you wanted the text to flow under the figure if it was long. I noticed that you are using \wrapfigure which is specifically designed for this, however the image you show for what you want does not show this. I assumed that you wanted to the text to flow under. If not, a simpler solution would be to use minipages instead of wrapfigure.

Here is the code:

\documentclass [12pt]{article}
\usepackage[demo]{graphicx}% remove [demo] for real document
\usepackage[usenames,dvipsnames]{color}
\usepackage{lipsum}
\usepackage{needspace} % got it from http://www.tex.ac.uk/CTAN/macros/latex/contrib/needspace/
\usepackage{wrapfig}
\usepackage[a4paper, margin=1cm, left=2cm, right=2cm, top=1cm, bottom=1.5cm, landscape, ignorehead] {geometry}

\usepackage{xparse}% For optional args

\newcommand{\justWarningHead}[1]{%
  \needspace{5\baselineskip}\colorbox{Black}{\parbox{\linewidth}{\color{White}\textbf{#1}}}\nopagebreak[0]\vspace{2px}%
}

\NewDocumentCommand{\WarningHeading}{o o o o o m}{% up to 4 figures
\IfNoValueTF{#2}{}{%
  \setlength{\intextsep}{-4pt}% Adjustment for the addtional vertical space form the \colorbox
  \begin{wrapfigure}{r}[0pt]{#1\linewidth}%
    \raggedleft% right align the figures
    \includegraphics[width=0.95\linewidth]{#2}%
}
\IfNoValueTF{#3}{}{\par\medskip\includegraphics[width=0.95\linewidth]{#3}}% Should be nested for
\IfNoValueTF{#4}{}{\par\medskip\includegraphics[width=0.95\linewidth]{#4}}% efficiency. This way 
\IfNoValueTF{#5}{}{\par\medskip\includegraphics[width=0.95\linewidth]{#5}}% is easier to read
\IfNoValueTF{#2}{}{\end{wrapfigure}}%
\justWarningHead{#6}%
}

\newcommand{\warrningtext}[1]{%
  {{\textbf{#1}}\vspace{2px}}% removed leading \vspace here
}

\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\begin{document}
\color{red}
\WarningHeading[0.31][pic1]{WARNING - with one picture}
\warrningtext{\lipsum[1]}

\color{black}
\WarningHeading{WARNING - with no pictures}
\warrningtext{\lipsum[2]}

\color{blue}
\WarningHeading[0.31][pic3][pic4]{WARNING - with 2 images}
\warrningtext{\lipsum[1-2]}

\color{green}
\WarningHeading[0.31][pic5][pic6][pic7]{WARNING - with 3 images}
\warrningtext{\lipsum[1-3]}

\color{black}
\WarningHeading[0.31][pic8][pic9][pic10][pic11]{WARNING - with 4 images}
\warrningtext{\lipsum[1-3]}

\color{red}
\WarningHeading{WARNING - with no pictures}
\warrningtext{\lipsum[4]}

\color{blue}
\WarningHeading[0.31][pic1]{WARNING - with one picture}
\warrningtext{\lipsum[1]}

\color{black}
\WarningHeading[0.15][pic8][pic9][pic10][pic11]{WARNING - with 4 images}
\warrningtext{\lipsum[1-3]}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.