{"action":"created","issue":{"url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/1728","repository_url":"https://api.github.com/repos/sphinx-doc/sphinx","labels_url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/1728/labels{/name}","comments_url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/1728/comments","events_url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/1728/events","html_url":"https://github.com/sphinx-doc/sphinx/issues/1728","id":57727274,"number":1728,"title":"Feature request: multiple elements in \"floating\" block","user":{"login":"Jellby","id":7943459,"avatar_url":"https://avatars.githubusercontent.com/u/7943459?v=3","gravatar_id":"","url":"https://api.github.com/users/Jellby","html_url":"https://github.com/Jellby","followers_url":"https://api.github.com/users/Jellby/followers","following_url":"https://api.github.com/users/Jellby/following{/other_user}","gists_url":"https://api.github.com/users/Jellby/gists{/gist_id}","starred_url":"https://api.github.com/users/Jellby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jellby/subscriptions","organizations_url":"https://api.github.com/users/Jellby/orgs","repos_url":"https://api.github.com/users/Jellby/repos","events_url":"https://api.github.com/users/Jellby/events{/privacy}","received_events_url":"https://api.github.com/users/Jellby/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sphinx-doc/sphinx/labels/latex","name":"latex","color":"FFFFFF"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-15T11:30:59Z","updated_at":"2016-03-01T10:01:58Z","closed_at":null,"body":"I'd like to have several images, several tables or several code blocks wrapped in a single \"figure\", \"table\" or \"code-block\", with a single caption. This is especially important for the LaTeX writer, where these elements can float to different places, and they need to be kept together.\r\n\r\nThe syntax for tables would be trivial: include several tables in the \"table\" directive, instead of just one. For figures and code-blocks something else may be needed.\r\n"},"comment":{"url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/comments/190643429","html_url":"https://github.com/sphinx-doc/sphinx/issues/1728#issuecomment-190643429","issue_url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/1728","id":190643429,"user":{"login":"Jellby","id":7943459,"avatar_url":"https://avatars.githubusercontent.com/u/7943459?v=3","gravatar_id":"","url":"https://api.github.com/users/Jellby","html_url":"https://github.com/Jellby","followers_url":"https://api.github.com/users/Jellby/followers","following_url":"https://api.github.com/users/Jellby/following{/other_user}","gists_url":"https://api.github.com/users/Jellby/gists{/gist_id}","starred_url":"https://api.github.com/users/Jellby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jellby/subscriptions","organizations_url":"https://api.github.com/users/Jellby/orgs","repos_url":"https://api.github.com/users/Jellby/repos","events_url":"https://api.github.com/users/Jellby/events{/privacy}","received_events_url":"https://api.github.com/users/Jellby/received_events","type":"User","site_admin":false},"created_at":"2016-03-01T10:01:58Z","updated_at":"2016-03-01T10:01:58Z","body":"If it helps, I'm using this custom extension, which seems to work for me:\r\n\r\n```\r\nfrom docutils import nodes\r\nfrom docutils.parsers.rst import Directive, directives\r\nfrom docutils.statemachine import ViewList\r\nfrom sphinx.util.nodes import set_source_info\r\n\r\nclass float_container(nodes.General, nodes.Element): pass\r\nclass table_container(nodes.General, nodes.Element): pass\r\nclass figure_container(nodes.General, nodes.Element): pass\r\nclass code_container(nodes.General, nodes.Element): pass\r\n\r\n# Create the float directive\r\n#\r\nclass FloatDirective(Directive):\r\n  has_content = True\r\n  required_arguments = 0\r\n  optional_arguments = 0\r\n  final_argument_whitespace = False\r\n  option_spec = {\r\n    'type': directives.unchanged_required,\r\n    'caption': directives.unchanged_required,\r\n    'caption-top': directives.flag,\r\n    'name': directives.unchanged,\r\n  }\r\n\r\n  def run(self):\r\n    if (self.options.get('type') == 'table'):\r\n      content_node = table_container('')\r\n    elif (self.options.get('type') == 'figure'):\r\n      content_node = figure_container('')\r\n    elif (self.options.get('type') == 'code'):\r\n      content_node = code_container('')\r\n    else:\r\n      content_node = float_container('')\r\n    self.state.nested_parse(self.content, self.content_offset, content_node)\r\n    set_source_info(self, content_node)\r\n    self.add_name(content_node)\r\n    caption = self.options.get('caption')\r\n    if caption:\r\n      parsed = nodes.Element()\r\n      self.state.nested_parse(ViewList([caption], source=''), self.content_offset, parsed)\r\n      caption_node = nodes.caption(parsed[0].rawsource, '', *parsed[0].children)\r\n      caption_node.source = parsed[0].source\r\n      caption_node.line = parsed[0].line\r\n      if ('caption-top' in self.options):\r\n        content_node.insert(0, caption_node)\r\n      else:\r\n        content_node += caption_node\r\n    return [content_node]\r\n\r\ndef visit_float_html(self, node):\r\n  self.body.append(self.starttag(node, 'div', CLASS='float-wrapper'))\r\n\r\ndef depart_float_html(self, node):\r\n  self.body.append('</div>\\n')\r\n\r\ndef visit_float_latex(self, node):\r\n  ids = ''\r\n  for id in self.pop_hyperlink_ids('float'):\r\n    ids += self.hypertarget(id, anchor=False)\r\n  if node['ids']:\r\n    ids += self.hypertarget(node['ids'][0], anchor=False)\r\n  if (isinstance(node, table_container)):\r\n    floattype = 'table'\r\n  elif (isinstance(node, figure_container)):\r\n    floattype = 'figure'\r\n  elif (isinstance(node, code_container)):\r\n    floattype = 'code'\r\n  else:\r\n    floattype = 'float'\r\n  self.body.append('\\\\begin{%s}\\n' % floattype)\r\n  if any(isinstance(child, nodes.caption) for child in node):\r\n    self.body.append('\\\\capstart\\n')\r\n  self.context.append(ids + '\\\\end{%s}\\n' % floattype)\r\n\r\ndef depart_float_latex(self, node):\r\n  self.body.append(self.context.pop())\r\n\r\n# Setup\r\n#\r\ndef setup(app):\r\n  app.add_directive('float', FloatDirective)\r\n  app.add_node(float_container,\r\n               html=(visit_float_html, depart_float_html),\r\n               latex=(visit_float_latex, depart_float_latex))\r\n  app.add_enumerable_node(table_container, 'table',\r\n               html=(visit_float_html, depart_float_html),\r\n               latex=(visit_float_latex, depart_float_latex))\r\n  app.add_enumerable_node(figure_container, 'figure',\r\n               html=(visit_float_html, depart_float_html),\r\n               latex=(visit_float_latex, depart_float_latex))\r\n  app.add_enumerable_node(code_container, 'code-block',\r\n               html=(visit_float_html, depart_float_html),\r\n               latex=(visit_float_latex, depart_float_latex))\r\n```\r\n\r\nThen use it as:\r\n\r\n```\r\n.. float::\r\n   :type: figure \r\n   :caption: This \"figure\" is just a couple of paragraphs\r\n   :name: figure_wrapper\r\n\r\n   First paragraph inside a figure\r\n\r\n   Second paragraph inside a figure\r\n```\r\n\r\nAny chance something like this could be included? Should I create a pull request? Modifications?"}}