1

When compiling figure with tint box it's showing ERROR. How to achieve sidebyside (it's means text is leftside and figure is rightside). My MWE is:

\documentclass{article}
\usepackage{lipsum,fancybox,pbox,graphics}
\usepackage[many]{tcolorbox}
\usepackage{floatrow}
\usepackage{caption}
\usepackage{graphicx}
\makeatletter
\newenvironment{textbyfigure}[2][0.75em]{%
  \leavevmode
  \begin{Sbox}\hbox{#2}\end{Sbox}%
  \settowidth{\figureboxwidth}{\TheSbox}%
  \setlength{\textboxwidth}{\linewidth}%
  \addtolength{\textboxwidth}{-\figureboxwidth}%
  \addtolength{\textboxwidth}{-1.5em}%
  \begin{Sbox}\hbox{#2}\end{Sbox}%
  \setlength{\saveparskip}{\parskip}
  \noindent\begin{minipage}[t]{\textboxwidth}\ignorespaces
}{%
  \end{minipage}%
  \hfill
  \vspace{1ex}
}
\DeclareCaptionFormat{tcbcaption}{%
  \begin{tcolorbox}[
    nobeforeafter,
    enhanced,
    colback=white,
    arc=0pt,
    outer arc=0pt,
    boxrule=0pt,
    colupper=white,
    fontupper=\large\sffamily,
    boxsep=0pt,
    watermark opacity=1,
    watermark graphics=lichtspiel.jpg,
    watermark overzoom=1.0
  ]
  #1#2#3
  \end{tcolorbox}%
}
\captionsetup{format=tcbcaption,labelformat=empty}
\makeatother

\begin{document}
\lipsum[1]
\lipsum[2]

\begin{figure}
\ffigbox[\FBwidth]
  {\includegraphics{16627fig01_02}}
  {\caption{how many factors are there in a set of 12?}}
\end{figure}

\begin{textbyfigure}{\begin{figure}
\ffigbox[\FBwidth]{\includegraphics{16627fig01_02}}
  {\caption{The
Roman numerals on this stone show the distance to the next village.}}}
Throughout the ages and in different countries, number systems were     developed and used to help people
count and communicate with numbers. From the ancient Egyptians to     the modern day, different systems have
used pictures and symbols to represent whole numbers. Some of the     well-known number systems are the
Egyptian, Babylonian, Roman, modern Chinese and the Hindu-Arabic or     decimal system.
\end{textbyfigure}

\end{document}
  • Could you please add to your question an image showing how is the desired output? – Gonzalo Medina Feb 5 '15 at 2:10
  • @Gonzalo: Updated my questions – Balaji Feb 5 '15 at 2:13
  • Ah, the reason for the error is that you are placing a floating object (figure) inside a minipage and this, of course, triggers the error. Now that I see what you are trying to achieve, a new approach is better. In some minutes I'll provide an answer. – Gonzalo Medina Feb 5 '15 at 3:06
  • @GonzaloMedina: Thanks and waiting for answer. – Balaji Feb 5 '15 at 4:05
3

Here is answer which is also connected to figure caption inside float with float. I gave an alternative to your original textbyfigure environment, but you can stay with your version also:

\documentclass{article}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\usepackage{caption}

\newcommand{\mygraphics}[3][]{%
  \tcbincludegraphics[nobeforeafter,
    blanker,hbox,
    minipage boxed title*=-6mm,
    title={\captionsetup{skip=0pt}\captionof{figure}{#3}},
    attach boxed title to bottom center,
    boxed title style={enhanced,size=title,sharp corners,
      boxrule=0pt,frame hidden,colback=green!50!black!25},
    #1]{#2}%
}

\newsavebox\mysavebox

\newenvironment{textbyfigure}[1]{%
  \sbox{\mysavebox}{#1}%
  \begin{tcolorbox}[blanker,
    beforeafter skip=8pt,
    sidebyside,sidebyside gap=5mm,
    sidebyside align=top,
    righthand width=\wd\mysavebox,]%
}{%
  \tcblower%
  \raisebox{\the\dimexpr-\ht\mysavebox-\dp\mysavebox+\baselineskip/2\relax}{\usebox{\mysavebox}}%
  \end{tcolorbox}
}

\begin{document}

\lipsum[1]

\begin{textbyfigure}{
  \mygraphics[graphics options={scale=0.4}]{Wing.png}
    {The Roman numerals on this stone show the distance to the next village.}}
Throughout the ages and in different countries, number systems were developed
and used to help people count and communicate with numbers. From the ancient
Egyptians to the modern day, different systems have used pictures and symbols to
represent whole numbers. Some of the well-known number systems are the Egyptian,
Babylonian, Roman, modern Chinese and the Hindu-Arabic or decimal system.
\end{textbyfigure}

\lipsum[2]

\end{document}

enter image description here

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.