3

I'm trying to create some exercises along with sample solutions. For each solution I want a small table on the left with the data from the exercise description and the actual calculations plus explanations for them on the right.

To achieve this I'm using the wrapfig package. Unfortunately the solution doesn't wrap to the right of the data table – it instead appears above the table, under the exercise description.

How do I get the solution to actually wrap the data table, instead of jumping above it?

MWE:

% !TeX program = xelatex
\documentclass{article}

\usepackage{wrapfig}

\newenvironment{data}[1]%
{\begin{wraptable}{l}{#1}\begin{tabular}{|l|}\hline}%
        {\hline\end{tabular}\end{wraptable}}
\newcommand{\goals}{\hline}

\begin{document}
    \section{Calculating}
    \subsection{Addition}
    $\alpha=30$° and $\beta=15$°. Divide $\alpha$ with $\beta$!

    \begin{data}{2cm}
        $\alpha=30$°\\
        $\beta=15$°\\
        \goals
        $\gamma=?$\\
    \end{data}

    This is the formula:

    $\gamma=\frac{\alpha}{\beta}$

    This is the actual calculation:

    $\gamma=\frac{30°}{15°}=2$°

    Hopefully this was easy!
\end{document}

Result:

image showing the output of the MWE

Mockup of the desired result:

image showing the rough desired output

3

As explained by Christian Hupfer in this answer, the wrap environments are not real environments. So you need to work with \beginwraptable and \endwraptable instead. I also used the opportunity to replace the degree symbols by the corresponding \si syntax.

\documentclass{article}
\usepackage{siunitx}

\usepackage{wrapfig}

\newenvironment{data}%
{\wraptable{l}{0pt}% 
\begin{tabular}{|l|}\hline}%
        {\hline\end{tabular}\endwraptable}
\newcommand{\goals}{\hline}

\setlength\intextsep{0pt}% from https://tex.stackexchange.com/a/247109/121799
\begin{document}
    \section{Calculating}
    \subsection{Addition}
    $\alpha=\ang{30}$ and $\beta=\ang{15}$. Divide $\alpha$ with $\beta$!

    \begin{data}
        $\alpha=\ang{30}$\\
        $\beta=\ang{15}$\\
        \goals
        $\gamma=?$\\
    \end{data}
    This is the formula:

    $\gamma=\frac{\alpha}{\beta}$

    This is the actual calculation:

    $\gamma=\frac{\ang{30}}{\ang{15}}=\ang{2}$

    Hopefully this was easy!
\end{document}

enter image description here

NOTE: I was unable to set \setlength\intextsep{0pt} locally as in this answer.

  • Surely \SI{30}{\degree} should be used instead? – Troy May 12 '18 at 18:07
  • That indeed helps with getting the text to the right. Is there anything that could be done to get the text on the right to align with the top of the table on the left, though? – tambre May 12 '18 at 18:14
  • @marmot Yes? Sorry I don't see what you're getting at. It works, but it's wrong. The argument for \si is only meant to be units, not numbers. But yes, \ang works too. – Troy May 12 '18 at 18:33
  • @Troy No worries. This just happens to be a question on \wraptable, not siunitx, and the outputs of all three options are the same (AFAIK). Anyway, thanks for correcting that! – user121799 May 12 '18 at 18:35
  • @tambre I posted something that removes the vertical space. – user121799 May 12 '18 at 18:36

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.