LyXWrong referencing for subtables (sub table)

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
pooz
Posts: 65
Joined: Sat Apr 11, 2009 10:47 am

Wrong referencing for subtables (sub table)

Post by pooz »

Hi,

I got a floating table and put 2 subtables into it (below the legend and also as floating tables.). Then I put a marker in each sub table (in the beginning of a legend).

Problem: When referencing to the subtables, they got an incremented number. That means:

Code: Select all

1.1 Maintable
2.1a Subtable_A
2.1b Subtable_B
Here the Latex-Code:

Code: Select all

%% LyX 1.6.4.2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[ngerman,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\usepackage{babel}

\begin{document}
\selectlanguage{ngerman}%
You can see in Table \ref{tab:TableVor} and \ref{tab:TableHint}%
\begin{table}
\noindent \begin{centering}
\caption{\label{tab:Look-Up-Table-f=0000FCr-Zehnerpotenz}Main Floating-Table
title here.}

\par\end{centering}

\noindent \centering{}\subfloat[\label{tab:TableVor}subtable title-A]{\noindent \centering{}\begin{tabular}{|c|c|c|}
\hline 
$i$ & $x_{i}$ & $\mathrm{pow}(10,x_{i})$\tabularnewline
\hline
\hline 
$0$ & $-0.3188$ & $0.48$\tabularnewline
\hline 
$\vdots$ & $\vdots$ & $\vdots$\tabularnewline
\hline 
$2^{k}-1$ & $0.6435$ & $4.40$\tabularnewline
\hline
\end{tabular}}~~~~~~~~~~~~~~~ \subfloat[\label{tab:TableHint}subtable title-B]{\noindent \centering{}\begin{tabular}{|c|c|}
\hline 
$i$ & $\mathrm{pow}(10,x_{i})$\tabularnewline
\hline
\hline 
$0$ & $0.48$\tabularnewline
\hline 
$\vdots$ & $\vdots$\tabularnewline
\hline 
$2^{k}-1$ & $4.40$\tabularnewline
\hline
\end{tabular}}
\end{table}
\selectlanguage{english}

\end{document}
I could not solve the problem.
I would be glad, if someone could help !!!

For testing purpose I attached a zip-file containing both the LaTeX and LyX-File.

PS:
Why are the legends of subtables below the table, even if I put them above them?
Attachments
Archiv.zip
(1.92 KiB) Downloaded 306 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Re: Wrong referencing for subtables (sub table)

Post by Juanjo »

Looking at the LaTeX code, one sees that the caption command is enclosed in a centering environment. If you comment out or remove such environment, things work as expected. You should consider how you entered in LyX the caption for the whole table in order to avoid the insertion in the LaTeX code of such environment.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
pooz
Posts: 65
Joined: Sat Apr 11, 2009 10:47 am

Wrong referencing for subtables (sub table)

Post by pooz »

Your solution works for my given example above, even I did not understand, why a centering-command can mess up the numbering.


Unfortunately I made a mistake and did not post the same preamble/header of the defective LyX/Latex File. Because with that, it still does not work. Here is the right one:

Code: Select all

%% LyX 1.6.4.2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[12pt,english,ngerman]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3.5cm,bmargin=3.5cm,lmargin=3cm,rmargin=3cm}
\pagestyle{headings}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{color}
\usepackage{babel}

\usepackage{varioref}
\usepackage{float}
\usepackage{units}
\usepackage{textcomp}
\usepackage{amsmath}
\usepackage{makeidx}
\makeindex
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage[unicode=true, 
 bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=1,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true]
 {hyperref}
\hypersetup{pdftitle={e},
 pdfauthor={P},
 pdfsubject={S},
 pdfkeywords={S},
 linkcolor=black, citecolor=black, urlcolor=blue,  filecolor=blue,pdfpagelayout=OneColumn, pdfnewwindow=true, pdfstartview=XYZ, plainpages=false, pdfpagelabels}
 
\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\newcommand{\noun}[1]{\textsc{#1}}
\newcommand{\lyxmathsym}[1]{\ifmmode\begingroup\def\b@ld{bold}
  \text{\ifx\math@version\b@ld\bfseries\fi#1}\endgroup\else#1\fi}

%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}
%% A simple dot to overcome graphicx limitations
\newcommand{\lyxdot}{.}

\floatstyle{ruled}
\newfloat{algorithm}{tbp}{loa}[chapter]
\floatname{algorithm}{Algorithm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\newenvironment{lyxcode}
{\par\begin{list}{}{
\setlength{\rightmargin}{\leftmargin}
\setlength{\listparindent}{0pt}% needed for AMS classes
\raggedright
\setlength{\itemsep}{0pt}
\setlength{\parsep}{0pt}
\normalfont\ttfamily}%
 \item[]}
{\end{list}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
% DO NOT ALTER THIS PREAMBLE!!!
%
%This preamble is designed to ensure that the document prints
% out as advertised. If you mess with this preamble,
% parts of the document may not print out as expected.  If you
% have problems LaTeXing this file, please contact 
% the documentation team
% email: lyx-docs@lists.lyx.org

\usepackage{ifpdf} % part of the hyperref bundle
\ifpdf % if pdflatex is used

 % set fonts for nicer pdf view
 \IfFileExists{lmodern.sty}{\usepackage{lmodern}}{}

\fi % end if pdflatex is used

% Die Seiten des Inhaltsverzeichnisses werden rˆmisch numeriert,
% ein PDF-Lesezeichen f¸r das Inhaltsverzeichnis wird hinzugef¸gt
\let\myTOC\tableofcontents
\renewcommand\tableofcontents{%
  \frontmatter
  \pdfbookmark[1]{\contentsname}{}
  \myTOC
  \mainmatter }

% redefine the \LyX macro for PDF bookmarks
\def\LyX{\texorpdfstring{%
  L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
  {LyX}}

\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\begin{document}


 die Tabellen \ref{tab:TableVor}
und \ref{tab:TableHint}.%
\begin{table}
\noindent\caption{\label{tab:Look-Up-Table-f=0000FCr-Zehnerpotenz}Look-Up-Table f¸r
Zehnerpotenz mit $k=8$.}
\subfloat[\label{tab:TableVor}mit redundanter Eingabespalte $x_{i}$]{\noindent \begin{tabular}{|c|c|c|}
\hline 
$i$ & $x_{i}$ & $\mathrm{pow}(10,x_{i})$\tabularnewline
\hline
\hline 
$0$ & $-0.3188$ & $0.48$\tabularnewline
\hline 
$\vdots$ & $\vdots$ & $\vdots$\tabularnewline
\hline 
$2^{k}-1$ & $0.6435$ & $4.40$\tabularnewline
\hline
\end{tabular}}~~~~~~~~~~~~~~~ \subfloat[\label{tab:TableHint}mit direkter Referenzierung ¸ber Index $i$ ]{\noindent \begin{tabular}{|c|c|}
\hline 
$i$ & $\mathrm{pow}(10,x_{i})$\tabularnewline
\hline
\hline 
$0$ & $0.48$\tabularnewline
\hline 
$\vdots$ & $\vdots$\tabularnewline
\hline 
$2^{k}-1$ & $4.40$\tabularnewline
\hline
\end{tabular}}
\end{table}


\end{document}
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Wrong referencing for subtables (sub table)

Post by sommerfee »

Use

Code: Select all

\captionsetup[table]{position=t}
right after \usepackage{subfig}. For details take a look at the subfig package documentation, keyword "position option".
pooz
Posts: 65
Joined: Sat Apr 11, 2009 10:47 am

Wrong referencing for subtables (sub table)

Post by pooz »

Thanks, sommerfee, for your help,

I wonder, that I only see another part of the preamble in LyX. The Preamble I posted is only availible, when exporting the LyX-file to latex.

The only Preamble I can see in Lyx is this:

Code: Select all

% DO NOT ALTER THIS PREAMBLE!!!
%
%This preamble is designed to ensure that the document prints
% out as advertised. If you mess with this preamble,
% parts of the document may not print out as expected.  If you
% have problems LaTeXing this file, please contact 
% the documentation team
% email: lyx-docs@lists.lyx.org

\usepackage{ifpdf} % part of the hyperref bundle
\ifpdf % if pdflatex is used

 % set fonts for nicer pdf view
 \IfFileExists{lmodern.sty}{\usepackage{lmodern}}{}

\fi % end if pdflatex is used

% Die Seiten des Inhaltsverzeichnisses werden römisch numeriert,
% ein PDF-Lesezeichen für das Inhaltsverzeichnis wird hinzugefügt
\let\myTOC\tableofcontents
\renewcommand\tableofcontents{%
  \frontmatter
  \pdfbookmark[1]{\contentsname}{}
  \myTOC
  \mainmatter }

% redefine the \LyX macro for PDF bookmarks
\def\LyX{\texorpdfstring{%
  L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
  {LyX}}
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Wrong referencing for subtables (sub table)

Post by Juanjo »

Sommerfee,

Your suggestion would work if the document class were book, but it is scrbook in the code provided by pooz.

Pooz,
I think there are several possible solutions:
  • In every table, replace \caption by \captionabove. This may be difficult (or impossible) in LyX, unless you use ERT to write captions.
  • Go to Document > Configuration > Document class (or something similar; menus in my LyX editor are not in English). Then add

    Code: Select all

    captions=tableheading
    as an option for the document class. In the source code, check that you get

    Code: Select all

    \documentclass[12pt,english,ngerman,captions=tableheading]{scrbook}
    
    Then, in Document > Configuration > LaTeX preamble, include

    Code: Select all

    \captionsetup[subtable]{position=b}
    Check that this line appears after \usepackage{subfig} in the source code. If not, replace the above line by

    Code: Select all

    \AtBeginDocument{\captionsetup[subtable]{position=b}}
I hope this solves the problem.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
pooz
Posts: 65
Joined: Sat Apr 11, 2009 10:47 am

Wrong referencing for subtables (sub table)

Post by pooz »

Thank you very much, Juanjo,

for your help! Your soloution

Code: Select all

AtBeginDocument{\captionsetup[subtable]{position=b}
works perfectly!

But is it normal for this document class, that the caption of subtable are below, than above the tables (like it is for the top-table?)
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Wrong referencing for subtables (sub table)

Post by Juanjo »

pooz wrote: But is it normal for this document class, that the caption of subtable are below, than above the tables (like it is for the top-table?)
I thought it was what you wanted. If you want all table and subtable captions above, simply remove \captionsetup from the preamble.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
pooz
Posts: 65
Joined: Sat Apr 11, 2009 10:47 am

Wrong referencing for subtables (sub table)

Post by pooz »

My problem was, that the referencing number in the printed verision was wrong. The subtables were named 2.x, although the caption of the maintable, where the subtables are added to, were named 1.x.

Code: Select all

    1.1 Maintable
    2.1a Subtable_A
    2.1b Subtable_B
But with your solution this is solved. The only small thing remainded, is that the titles should go above the tables.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Wrong referencing for subtables (sub table)

Post by Juanjo »

pooz wrote:My problem was, that the referencing number in the printed verision was wrong.
I know. This is solved by means of the document class option captions=tableheading.
pooz wrote: The only small thing remainded, is that the titles should go above the tables.
As I already said, if subtable captions should go above the corresponding subtables, then you don't need \captionsetup in the preamble. Omit this part of the solution I posted before.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply