TransWikia.com

paracol and lettrine - problems with small paragraphs

TeX - LaTeX Asked on June 17, 2021

If I use lettrine inside a paracol environment and parindent is set to 0mm, the following problem arises if the paragraph on both sides is just one line:

There is no indentation in the next line and the text is overlapping with the text of lettrine.

How can I detect the paragraphs that consists of just one line and automatically add the needed indentation for the next paragraph? (Lettrine is used about 2000 times in documents with different page width, manual adjustment is not an option.)

enter image description here

    documentclass[a5paper,twoside]{article}
    usepackage{geometry}
    usepackage{paracol}
    usepackage{lettrine}
    
    setlength{columnsep}{3mm}
    setlength{parindent}{0mm}
    
    begin{document}
    
    begin{paracol}{2}
    switchcolumn[0]
    
    lettrine{1}
    Not much text
    
    switchcolumn
    
    lettrine{1}
    And again
    
    switchcolumn*
    
    Some text
    Some text
    Some text
    Some text
    Some text
    Some text
    Some text
    Some text
    Some text
    
    switchcolumn
    
    Some other text
    Some other text
    Some other text
    Some other text
    Some other text
    Some other text
    Some other text
    
    switchcolumn*
    
    lettrine{2}
    Some text
    Some text
    Some text
    Some text
    Some text
    Some text
    Some text
    Some text
    Some text
    
    switchcolumn
    
    lettrine{2}
    Some other text
    Some other text
    Some other text
    Some other text
    Some other text
    Some other text
    Some other text
    
    switchcolumn*
    
    end{paracol}
    
    end{document}

As @John Kormylo pointed out, this is not a problem of paracol.

My solution, based on his answer, is as follows:

enter image description here

documentclass[a5paper,twoside]{article}
usepackage{geometry}
usepackage{paracol}
usepackage{lettrine}
usepackage{lipsum}

setlength{columnsep}{3mm}
setlength{parindent}{0mm}

newlength{CLFL}% Custom length for lettrine
newlength{IFLL}% Indentation for lettrine left
newlength{IFLR}% Indentation for lettrine right
setlength{IFLL}{0pt}
setlength{IFLR}{0pt}

makeatletter
newcommand{lettrineLeft}[2]% #1=letter, #2=paragraph
{bgroup
    setbox0=vbox{lettrine{#1}{}{globalCLFL=dimexpr L@height-L@lraise-htstrutbox} #2}%
    setlength{@tempdima}{dimexpr CLFL-ht0-dp0}
    ifdim@tempdima> -10pt
    setbox0=hbox{lettrine{#1}{}{[email protected]}}
    fi
    egroup
    lettrine{#1}{} #2}
makeatother

makeatletter
newcommand{lettrineRight}[2]% #1=letter, #2=paragraph
{bgroup
    setbox0=vbox{lettrine{#1}{}{globalCLFL=dimexpr L@height-L@lraise-htstrutbox} #2}%
    setlength{@tempdima}{dimexpr CLFL-ht0-dp0}
    ifdimIFLL> 0pt
    ifdim@tempdima> -10pt
    setbox0=hbox{lettrine{#1}{}{[email protected]}}
    fi
    else
    globalsetlength{IFLL}{0pt}
    fi
    egroup
    lettrine{#1}{} #2}
makeatother

newcommand{indentLeft}{ifdimIFLL> 0pt hskipIFLLglobalsetlength{IFLL}{0pt}fi}
newcommand{indentRight}{ifdimIFLR> 0pt hskipIFLRglobalsetlength{IFLR}{0pt}fi}

begin{document}
    
    begin{paracol}{2}sloppy
        switchcolumn[0]
        
        lettrineLeft{100}{Not much text here.}
        
        switchcolumn
        
        lettrineRight{1}{NAnd again}
        
        switchcolumn*
        
        indentLeft Some text..a
        Some text
        Some text
        Some text
        Some text
        Some text
        Some text
        Some text
        Some text
        
        switchcolumn
        
        indentRight Some other text
        Some other text
        Some other text
        Some other text
        Some other text
        Some other text
        Some other text
        
        switchcolumn*
        
        lettrineLeft{2}{Some text
            Some text
            Some text
            Some text
            Some text
            Some text
            Some text
            Some text
            Some text}
        
        switchcolumn
        
        lettrineRight{2}{Some other text
            Some other text
            Some other text
            Some other text
            Some other text
            Some other text
            Some other text}
        
        switchcolumn*
        
        indentLeft
        Some text
        Some text
        Some text
        Some text
        Some text
        Some text
        Some text
        Some text
        Some text
        
        switchcolumn
        
        indentRight
        Some other text
        Some other text
        Some other text
        Some other text
        Some other text
        Some other text
        Some other text
        
        switchcolumn*
        
    end{paracol}
    
end{document}

One Answer

This solution requites you to add the entire paragraph as an argument. The computation is based of fooling around with different length registers until it looked right.

One should always end a paragraph with strut before switchcolumn* or other commands which break baselineskip.

documentclass[a5paper,twoside]{article}
usepackage{geometry}
usepackage{paracol}
usepackage{lettrine}
usepackage{lipsum}

setlength{columnsep}{3mm}
setlength{parindent}{0mm}

newlength{Ltht}

makeatletter
newcommand{latrine}[3]% #1=letter, #2=wirdm #3=rest of paragraogh
{bgroup
  setbox0=vbox{lettrine{#1}{#2}{globalLtht=dimexpr L@height-L@lraise-htstrutbox} #3strut}%
  setlength{@tempdima}{dimexpr Ltht-ht0-dp0}
  ifdim@tempdima> 0pt
    unvbox0vskip@tempdima
  else
    unvbox0
  fi
egroup}
makeatother  

begin{document}

begin{paracol}{2}
switchcolumn[0]

latrine{1}{}{Not much text}

switchcolumn

latrine{1}{}{And again}

switchcolumn*

Some text
Some text
Some text
Some text
Some text
Some text
Some text
Some text
Some textstrut

switchcolumn

Some other text
Some other text
Some other text
Some other text
Some other text
Some other text
Some other textstrut

switchcolumn*

latrine{2}{}{Some text
Some text
Some text
Some text
Some text
Some text
Some text
Some text
Some text}

switchcolumn

latrine{2}{}{Some other text
Some other text
Some other text
Some other text
Some other text
Some other text
Some other text}

switchcolumn*

end{paracol}

end{document}

Correct answer by John Kormylo on June 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP