2

I want to position a bytefield at the right side of the page. For that reason I use the wrapfig package. If I make the wrapfigure smaller than 0.8\textwidth it doesn't work. If it's 0.8\textwidth (or even wider) it looks crappy.

\newcommand{\messagestart}{\begin{wrapfigure}[p] \begin{centering} \begin{bytefield}[bitwidth=2em]{8} \\}
\newcommand{\messageend}[1]{\end{bytefield} \par\end{centering} \protect\caption{#1} \label{#1} \end{wrapfigure} }

I tried to reduce the bitwidth, but it still didn't go smaller than 0.8\textwidth. Is it anyhow possible to make it at least 0.5\textwidth?

Edit: Here's an example:

\documentclass[a4paper,ngerman,naustrian,DIV=12,BCOR=1cm]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{wrapfig}
\usepackage{bytefield}
\begin{document}
\chapter{Request}
    \messagestart
         \bitheader{0-7} \\

         \begin{rightwordgroup}{Type}
             \wordbox[tlr]{1}{0}
         \end{rightwordgroup} \\

         \begin{rightwordgroup}{Data}
             \wordbox[tblr]{4}{Data, 64 Bytes} 
         \end{rightwordgroup}

    \messageend{Request}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\end{document}
Nikolar
  • 77
  • please make a small complete document that shows the problem – David Carlisle Apr 05 '15 at 00:02
  • 1
    Welcome to TeX SE! Please post a minimal working example (MWE). Note that \centering is a command. centering is not an environment. Perhaps you wanted the center environment. bytefield is not a standard environment (and I've no idea where you have it from). wrapfigure and \gls both require packages (they aren't standard either). – cfr Apr 05 '15 at 00:02
  • As requested, I added the example. – Nikolar Apr 05 '15 at 00:19
  • You should use \newcommand{\messagestart}{\begin{wrapfigure}{r}{0.5\textwidth} \centering \begin{bytefield}[bitwidth=2em]{8} } \newcommand{\messageend}[1]{\end{bytefield} \par \protect\caption{#1} \label{#1} \end{wrapfigure} }. –  Apr 05 '15 at 00:38
  • Thanks for that quick reply, but that still does'nt work for me. – Nikolar Apr 05 '15 at 00:42

1 Answers1

2

I wouldn't even try to reduce things like that for so many fine tunings (for example, number of lines for wrapfigure[11] here) will be difficult to make. Use \centering not \begin{centering} BTW.

This is how you should be using it.

\documentclass[a4paper,ngerman,naustrian,DIV=12,BCOR=1cm]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{wrapfig}
\usepackage{bytefield}
\begin{document}
\chapter{Request}
    \begin{wrapfigure}[11]{r}{0.5\textwidth}
    \centering
    \begin{bytefield}[bitwidth=2em]{8}
         \bitheader{0-7} \\

         \begin{rightwordgroup}{Type}
             \wordbox[tlr]{1}{0}
         \end{rightwordgroup} \\

         \begin{rightwordgroup}{Data}
             \wordbox[tblr]{4}{Data, 64 Bytes}
         \end{rightwordgroup}

    \end{bytefield}
    \par
    \caption{Request} \label{request}
    \end{wrapfigure}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\end{document}

enter image description here

And here is your version:

\documentclass[a4paper,DIV=12,BCOR=1cm]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{wrapfig}
\usepackage{bytefield}
\newcommand{\messagestart}[1][]{\begin{wrapfigure}[#1]{r}{0.5\textwidth} \centering \begin{bytefield}[bitwidth=2em]{8}}
\newcommand{\messageend}[1]{\end{bytefield} \par \protect\caption{#1} \label{#1} \end{wrapfigure}}
\begin{document}
\chapter{Request}
    \messagestart[11]
         \bitheader{0-7} \\

         \begin{rightwordgroup}{Type}
             \wordbox[tlr]{1}{0}
         \end{rightwordgroup} \\

         \begin{rightwordgroup}{Data}
             \wordbox[tblr]{4}{Data, 64 Bytes}
         \end{rightwordgroup}

    \messageend{Request}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\end{document}

Picture same as above.

  • Is'nt it possible to make a command for this? Because I need this very often. I tried to add the number of lines to the command, but it also fails. The funny thing is, that it doesn't even appear at the line, but very later in the document. But it has to be that command, because if I only use "figure" instead of "wrapfigure" it works perfectly. – Nikolar Apr 05 '15 at 00:58
  • @Nikolar Have you seen the lower part of my answer? You have to add a width to wrapfigure. Please read the first two pages of wrapfig manual (texdoc wrapfig from command prompt). The positition specifier R allows to float and r doesn't. –  Apr 05 '15 at 01:05
  • Thank you! Finally with the R it works. But it positions the bytefields not really at the place, where I want them to. :D I guess, I'll have to invest a little bit of time, to get the result, which I want. – Nikolar Apr 05 '15 at 01:12
  • @Nikolar No R will make the figure to float, that means it can appear elsewhere. Better use r if you want it here. –  Apr 05 '15 at 01:20
  • I'm afraid, with r it does'nt work. Everytime I change it to r, it stops working. – Nikolar Apr 05 '15 at 01:33
  • @Nikolar Hmmm. Strange. It works for me. –  Apr 05 '15 at 01:41
  • I've placed the bytefield on another position and now it works. It seems like it can't be placed before a description list. – Nikolar Apr 05 '15 at 01:48
  • Btw how did you calculate the number of lines? – Nikolar Apr 05 '15 at 01:49
  • @Nikolar hehe, I counted ;-) Yes wrapfigure shouldn't be used in and around lists. Manual is very clear about it. –  Apr 05 '15 at 01:53