0

I am making this template for my notes, and I was trying to put an image (a logo) on the right side of a tcolorbox. The code is as follows:

\begin{tcbitemize}[raster equal height=rows, raster columns=2]
\tcbitem[blankest, add to natural space to=\myspace]
\begin{tcolorbox}[title=Hello, colframe=titlecolor]
\textbf{Overview:} blah blah
\end{tcolorbox}

\tcbitem[blankest, space to=\myspace] \includegraphics[width=2.5cm, height=2.5cm]{2.png}
\end{tcbitemize}

And the output is:

My output

But I have a few problems with this output:

  1. I would like the logo (the black square as the example here) to stick to the right side of the page (which isn't quite visible here as the background is white).
  2. Adjust the space between the box and the logo (for example set it to 1cm)
  3. The box has to fill the whole row (and not only fill half the row), so I can have my box fill the row (starting from left side of the page, and ending right before the logo).
  4. Adjust the height of the box to the maximum height; So if the box's height is less than the logo's height, the box's height would be increased automatically to be the same as the logo's, and if the box's height is greater, it's ok and nothing has ro be chenged).

I need to mention that there might be some other ways of doing a similar thing with tcblisting instead of tcbitemize, but I couldn't figure out their differences (as I'm new to this package), and which one would suite my needs better.

Thanks in advance.

2
  • please have a look at the partial answer below should meet your requirement 4 – js bibra Dec 3 '20 at 2:04
  • please see the revised answer -- time taken 6 hours – js bibra Dec 3 '20 at 5:42
1

(3 compilations are needed every time)

a partial answer -- removing the following line changes the box height automatically to the image height

    \tcbitem[blankest, space to=\myspace]

also if you add more text then the test box will increase size automatically -- I have kept the original code

            \textbf{Overview:} blah blah

and get the following result

enter image description here

now if I replace the above code with

            \textbf{Overview:} \lipsum[1]

I get the following result

enter image description here

Complete MWE

\documentclass{article}
\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage[most]{tcolorbox}
\tcbuselibrary{raster, skins}

\newlength{\mylen}

\begin{document}
        
    \begin{tcbitemize}[raster equal height=rows, raster columns=2]
%       \tcbitem[blankest, space to=\myspace]
        \begin{tcolorbox}[title=Hello, colframe=red!50!black]
            \textbf{Overview:} \lipsum[1]
        \end{tcolorbox}
        \tcbitem[blankest, space to=\myspace] \includegraphics[width=2.5cm, height=2.5cm]{2.png}
    \end{tcbitemize}
\end{document}

EDIT revised MWE to answer requirement 1,2,3 -- showframe is turned on for showing page borders -- the size of the image has been laid in terms of linewidth as well also for the left tcolorbox -- in addition force size has been set to false to allow the first column to be relaid

enter image description here

\documentclass{article}
\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage[most]{tcolorbox}
\tcbuselibrary{raster, skins}

\newlength{\mylen}
\usepackage[showframe]{geometry}
\begin{document}
    
    \begin{tcbitemize}[raster equal height=rows, raster columns=2, raster force size=false,
        ]
%       \tcbitem[blankest, space to=\myspace]
        \begin{tcolorbox}[title=Hello, colframe=red!50!black, right skip=0cm, add to width=0.3\linewidth]
            \textbf{Overview:} text
        \end{tcolorbox}
        \tcbitem[blankest, space to=\myspace] \includegraphics[width=0.4\linewidth]{2.png}
    \end{tcbitemize}
\end{document}

using lipsum in the left tcolorbox will now also expand auto downwards as per the requirement--

    \begin{tcbitemize}[raster equal height=rows, raster columns=2, raster force size=false,
        ]
%       \tcbitem[blankest, space to=\myspace]
        \begin{tcolorbox}[title=Hello, colframe=red!50!black, right skip=0cm, add to width=0.3\linewidth]
            \textbf{Overview:} \lipsum[1]
        \end{tcolorbox}
        \tcbitem[blankest, space to=\myspace] \includegraphics[width=0.4\linewidth]{2.png}
    \end{tcbitemize}

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.