TransWikia.com

Caption error with scrbook in combination with subfig

TeX - LaTeX Asked on June 7, 2021

I’ve recently updated the packages of my miktex distribution. Now I have a problem with the combination of KOMA script (scrbook) and the subfig package while compiling with LuaHBTeX.

The MWE gives me two errors about an "undefined control sequence". When I delete the subfig option caption=false it works. However, I use some KOMA options to change the appearance of the captions and I think I can remember that in this case the caption=false should be used.

What has changed since the previous versions I used?

  • Subfig: Update Package: subfig 2005/06/28 ver: 1.3 subfig package to not changed
  • scrbook: Update Document Class: scrbook 2018/03/30 v3.25 KOMA-Script document class (book) to Document Class: scrbook 2020/07/22 v3.31 KOMA-Script document class (book)

KOMA options for caption appearance:

addtokomafont{caption}{small}
renewcommandbfdefault{sb}
setkomafont{captionlabel}{smallsffamilybfseries}
setcapindent{1em}
newlength{lengthforcapwidth}
setlength{lengthforcapwidth}{10pt}
setcapwidth[c]{textwidth - lengthforcapwidth - lengthforcapwidth}

MWE:

documentclass [] {scrbook}

usepackage{subfig}

begin{document}

    begin{figure}[]%
        centering%
        subfloat[][Fig a]{%
            label{subfig:Figa}%
            %input{./Grafiken/TikzSource/FigaSource}}%
            }
        hfill%
        subfloat[][Fig b]{%
            label{subfig:Figb}%
            %input{./Grafiken/TikzSource/FigbSource}}%
            }
        caption{A description}%
        label{fig:notworking}%
    end{figure}


end{document}

One Answer

I would suggest to replace package subfig by subcaption. Then you can use the options of packages caption and subcaption for the layout of the captions:

documentclass [] {scrbook}

usepackage{subcaption}% loads caption
captionsetup[sub]{indention=0pt}

captionsetup{
  font=small,
  labelfont={sf,bf},
  format=plain,
  indention=1em,
  margin=10pt
}

renewcommandbfdefault{sb}
begin{document}
begin{figure}[htb]%
  centering
  subfloat[][Fig a]{%
    label{subfig:Figa}%
    rule{5cm}{2cm}%
  }%
  hfill
  subfloat[][Fig b]{%
    label{subfig:Figb}%
    rule{5cm}{2cm}%
  }%
  caption{A description}
  label{fig:notworking1}
end{figure}

begin{figure}[htb]%
  centering%
  subfloat[][Lorem ipsum dolor sit amet, consectetuer adipiscing elit.]
    {label{subfig:Figc}rule{5cm}{2cm}}%
  hfill
  subfloat[][Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin.]
    {label{subfig:Figd}rule{5cm}{2cm}}%
  caption{Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    Etiam lobortis facilisis sem.
    Nullam nec mi et neque pharetra sollicitudin.}
  label{fig:notworking2}
end{figure}
end{document}

enter image description here

Or you can use the KOMA-Script options:

documentclass [] {scrbook}

usepackage{subcaption}% loads caption
captionsetup[sub]{indention=0pt}

addtokomafont{caption}{small}
setkomafont{captionlabel}{sffamilybfseries}
setcapindent{1em}
newlength{lengthforcapwidth}
setlength{lengthforcapwidth}{10pt}
setcapwidth{dimexprtextwidth - 2lengthforcapwidthrelax}

renewcommandbfdefault{sb}
begin{document}
begin{figure}[htb]%
  centering
  subfloat[][Fig a]{%
    label{subfig:Figa}%
    rule{5cm}{2cm}%
  }%
  hfill
  subfloat[][Fig b]{%
    label{subfig:Figb}%
    rule{5cm}{2cm}%
  }%
  caption{A description}
  label{fig:notworking1}
end{figure}

begin{figure}[htb]%
  centering%
  subfloat[][Lorem ipsum dolor sit amet, consectetuer adipiscing elit.]
    {label{subfig:Figc}rule{5cm}{2cm}}%
  hfill
  subfloat[][Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin.]
    {label{subfig:Figd}rule{5cm}{2cm}}%
  caption{Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    Etiam lobortis facilisis sem.
    Nullam nec mi et neque pharetra sollicitudin.}
  label{fig:notworking2}
end{figure}
end{document}

enter image description here

 *File List*
 scrbook.cls    2020/07/22 v3.31 KOMA-Script document class (book)
scrkbase.sty    2020/07/22 v3.31 KOMA-Script package (KOMA-Script-dependent bas
ics and keyval usage)
 scrbase.sty    2020/07/22 v3.31 KOMA-Script package (KOMA-Script-independent b
asics and keyval usage)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
scrlfile.sty    2020/07/22 v3.31 KOMA-Script package (loading files)
tocbasic.sty    2020/07/22 v3.31 KOMA-Script package (handling toc-files)
scrsize11pt.clo    2020/07/22 v3.31 KOMA-Script font size class option (11pt)
typearea.sty    2020/07/22 v3.31 KOMA-Script package (type area)
subcaption.sty    2020/08/23 v1.3g Sub-captions (AR)
 caption.sty    2020/09/02 v3.5a Customizing captions (AR)
caption3.sty    2020/08/30 v2.0 caption3 kernel (AR)
caption-koma.sto    2020/08/22 v2.0 Adaption of the caption package to the KOMA
-Script document classes (AR)
l3backend-pdftex.def    2020-09-01 L3 backend support: PDF output (pdfTeX)
 ***********

Correct answer by esdd on June 7, 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