Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captions for Tables and Images #300

Open
jonnsn opened this issue Jul 1, 2014 · 7 comments
Open

Captions for Tables and Images #300

jonnsn opened this issue Jul 1, 2014 · 7 comments
Milestone

Comments

@jonnsn
Copy link
Contributor

jonnsn commented Jul 1, 2014

In Word you can right-click a table or an image and insert a caption for it which provides a short title or description and can be placed at top or bottom.
This way you can also insert a list of all tables or images in the document.
The Caption-Property (http:https://officeopenxml.com/WPtableCaption.php) seems not to be the right element for this purpose, as this adds a title in the table properties, which is not visible in the document itself.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@jonnsn jonnsn mentioned this issue Jul 1, 2014
@ivanlanin ivanlanin added this to the Later milestone Jul 1, 2014
@jonnsn
Copy link
Contributor Author

jonnsn commented Jul 2, 2014

I just analyzed a document.xml file.
Captions produce xml like this:

        <w:p w:rsidR="00574B8D" w:rsidRDefault="00574B8D" w:rsidP="00574B8D">
            <w:pPr>
                <w:pStyle w:val="Beschriftung"/>
                <w:keepNext/>
            </w:pPr>
            <w:r>
                <w:t xml:space="preserve">Tabelle </w:t>
            </w:r>
            <w:fldSimple w:instr=" SEQ Tabelle \* ARABIC ">
                <w:r>
                    <w:rPr>
                        <w:noProof/>
                    </w:rPr>
                    <w:t>1</w:t>
                </w:r>
            </w:fldSimple>
            <w:r>
                <w:t>:My Table caption</w:t>
            </w:r>
        </w:p>
        <w:p w:rsidR="00574B8D" w:rsidRDefault="00574B8D" w:rsidP="00574B8D">
            <w:pPr>
                <w:pStyle w:val="Beschriftung"/>
            </w:pPr>
            <w:fldSimple w:instr=" SEQ Abbildung \* ARABIC ">
                <w:r>
                    <w:rPr>
                        <w:noProof/>
                    </w:rPr>
                    <w:t>1</w:t>
                </w:r>
            </w:fldSimple>
            <w:r>
                <w:t>My Image caption</w:t>
            </w:r>
        </w:p>
        <w:p w:rsidR="004D1DFC" w:rsidRDefault="004D1DFC" w:rsidP="00574B8D">
            <w:pPr>
                <w:pStyle w:val="Beschriftung"/>
            </w:pPr>
            <w:bookmarkStart w:id="0" w:name="_GoBack"/>
            <w:bookmarkEnd w:id="0"/>
        </w:p>

I am not yet sure about all the parts (no experiences with ooxml), but this would be the way to go I think.

@jas0nkim
Copy link

I am looking for having this feature on PHPWord as well. 👍

@scalco19
Copy link

Do I also need this feature to update?

@arrabal
Copy link

arrabal commented Mar 16, 2017

@jonnsn did you ever manage to make it work? I need this feature too. Is it implemented in your fork? Thanks.

@arrabal
Copy link

arrabal commented Mar 17, 2017

I'm not big expert on OOXML but the xml produced by captions seems like a field according to http:https://officeopenxml.com/WPfieldInstructions.php

The key would be to add more functionality to Field class, to support the SEQ command. A quick implementation would consist in just addings two more elements to Field::fieldsArray: 'SEQ Figure' and 'SEQ Table', with standard options. Something like this:

        ...
        'SEQ Table'=>array(
            'properties'=>array(
                'format' => array('Arabic', 'ArabicDash', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN')
            ),
            'options'=>array('PreserveFormat')
         ),        
        'SEQ Figure'=>array(
            'properties'=>array(
                'format' => array('Arabic', 'ArabicDash', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN')
            ),
            'options'=>array('PreserveFormat')

I'm not sure if 'options'=>array('PreserveFormat') is strictly necessary and it could be just emptied, like, 'options' => array()

Additional instructions, as explained in http:https://officeopenxml.com/WPfieldInstructions.php can be added, but I don't feel it's really necessary for this purpose.

Then, you could just modify addTable and addImage methods to receive an optional 'caption' parameter so that when it's not null you add a text run after the image/table. In such text run, you can do something like:

  1. addTextRun()
  2. addText('Table ') or addText('Image ')
  3. addField('SEQ Table', array('format'=>'Arabic')) or addField('SEQ Image', array('format'=>'Arabic'))
  4. addText(' ' . $caption)

I know this is not elegant implementation. Table and Figure are just names I've chosen for table and image numbering lists.

Edit: Forgot to mention that, as happens in TOC numbers, all fields need to be refreshed manually when opening the document.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
@leandroxxxxx
Copy link

Any chance of this being implemented. Also, it would be interesting if a could refer this seq fields in the text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants