2

I have two problems.

  1. I have an mechanism. It gives me correct number of lines, which I should make narrow (I have it in \setcounter{ct}{...}). And I want to teach \addpicture that skill and use it as default for the first optional argument. How can I do it?

In nutshell I want default value of optional argument of \addpicture to be calculated every time running this macro based on mandatory arguments of function \addpicture.

But I see that I will not success in this case because the third agrument of \addpicture is not a number of narrow lines. So,

  1. The third argument of \InsertBoxL is number of additional lines which should be narrower too. In documentation it is said correction. But in my function it spoils due to some mystical things. So, what it is now, and what shall I do to correct it?

    enter image description here

    \documentclass{article}
    \usepackage{graphicx}              
    \usepackage{forloop}
    \usepackage{caption}
    \usepackage{xargs}
    \usepackage{mwe}    
    \input{insbox.tex}
    \usepackage{threeparttable}
    \newcounter{ct}
    
    \newlength\imageheight
    
    \newcount\narrowlinect
    \narrowlinect=0\relax
    
    \newcommandx\addpicture[4][1=5,3=0]{%
    \InsertBoxL{#3}{\begin{threeparttable}%
    \begin{tabular}{c@{}}\includegraphics[width=#4\textwidth]{#2}\end{tabular}%
    \captionof{figure}{}\end{threeparttable}}[#1]}
    
    \begin{document}
    \settoheight\imageheight{\includegraphics[width=0.45\textwidth]{example-image-a}}
    \narrowlinect=\imageheight\relax
    \setcounter{ct}{\numexpr((\narrowlinect)/\baselineskip+2)\relax}
    
    \arabic{ct}
    
    \addpicture[0]{example-image-a}[0]{0.45}
    \forloop{ct}{1}{\value{ct} < 30}{\arabic{ct}\newline }
    \end{document}
    
3

solution to the second question.

The first argument is the number of untouched lines, the second argument is the object to be inserted and the optional argument is a corrective term: the number of supplementary lines which should be narrower (w.r.t. the number of lines calculated by TeX) – just as in the wrapfigure environment.

I propose this simple code, which works fine for one-lined captions. For longer captions, you'll have to make a correction, in terms of the number of supplementary lines, with the command: \myInsertBoxL[no of supplementary lines]{width}{graphic file}{caption text}.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{mwe}
\input{insbox.tex}

\newcommand\myInsertBoxL[4][]{\InsertBoxL{0}{%
\parbox[t]{#2}{%
\includegraphics[width=#2]{#3}
\captionof{figure}{#4}
}}%
[\numexpr#1 + 3\relax]}

\usepackage{lipsum}

\begin{document}

\myInsertBoxL{0.45\textwidth}{example-image-a}{}
\noindent\lipsum[1-2]

\myInsertBoxL[2]{0.45\textwidth}{example-image-b}
{A useful caption. A useful caption. A useful caption.}%
\noindent\lipsum[3-5]

\end{document} 

enter image description here

  • @Bernand Hm. In my MWE I have zero in optional argument. Take a look at screenshot. 7 lines are narrower... not zero...btw, it is your construction of adding pictures (heh). – Lust_For_Love Mar 14 '16 at 19:11
  • @Bernand I understood the meaning of parametres. But, why does this construction spoil it?! – Lust_For_Love Mar 14 '16 at 19:28
  • and in wrapfigure it is number of ALL narrow lines. but there it is just correction - the number that will add to the number of lines calculated by TeX. Isn't it?! – Lust_For_Love Mar 14 '16 at 19:38
  • 1
    Yes. In my opinion, it is simpler than wrapfigure. – Bernard Mar 14 '16 at 20:28
  • @Bernand but you can see that with threeparttable spoils it. I need to add this correction not only for adding place for caption (for example), but in order to make normal wrapping... It is wrong. – Lust_For_Love Mar 14 '16 at 20:31

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.