# Using bytefield with wrapfigure

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

\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}
• please make a small complete document that shows the problem – David Carlisle Apr 5 '15 at 0:02
• 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 5 '15 at 0:02
• As requested, I added the example. – Nikolar Apr 5 '15 at 0:19
• Thanks for that quick reply, but that still does'nt work for me. – Nikolar Apr 5 '15 at 0:42

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}

\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}

\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]

\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 5 '15 at 0: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. – user11232 Apr 5 '15 at 1: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 5 '15 at 1:12
• @Nikolar No R will make the figure to float, that means it can appear elsewhere. Better use r if you want it here. – user11232 Apr 5 '15 at 1:20
• I'm afraid, with r it does'nt work. Everytime I change it to r, it stops working. – Nikolar Apr 5 '15 at 1:33