首页 \ 问答 \ Knitr和图标题在HTML中(Knitr and Figure Caption in HTML)

Knitr和图标题在HTML中(Knitr and Figure Caption in HTML)

knitr将参数fig.cap定义为

fig.cap:(NULL;字符)在LaTeX的图形环境中使用的图形标题(在\ caption {}中); 如果是NULL或NA,它将被忽略,否则图形环境将用于块中的图(在\ begin {figure}和\ end {figure}中输出)

但是,对于HTML输出以下工作:

---
title: "Caption Test"
author: "Some Author"
date: "February 18, 2016"
output: html_document
---

```{r}
library(ggplot2)
```

```{r, fig.cap = c("This is caption 1", "This is caption 2")}
## Plot 1
qplot(carat, price, data = diamonds)

## Plot 2
qplot(carat, depth, data = diamonds)
```

意思是,每个数字在代码块参数fig.cap = c("Caption 1", "Caption 2")定义了正确的标题

但是,要记住字幕 - 特别是长时间 - 当它们放置在大块选项中时,很难。 除了为每个图形创建两个单独的块并在字块外插入字幕之外,还有其他选项吗?


knitr defines the argument fig.cap as

fig.cap: (NULL; character) figure caption to be used in a figure environment in LaTeX (in \caption{}); if NULL or NA, it will be ignored, otherwise a figure environment will be used for the plots in the chunk (output in \begin{figure} and \end{figure})

However, for HTML output the following works:

---
title: "Caption Test"
author: "Some Author"
date: "February 18, 2016"
output: html_document
---

```{r}
library(ggplot2)
```

```{r, fig.cap = c("This is caption 1", "This is caption 2")}
## Plot 1
qplot(carat, price, data = diamonds)

## Plot 2
qplot(carat, depth, data = diamonds)
```

meaning, each figures gets its correct caption defined in the code chunk argument fig.cap = c("Caption 1", "Caption 2")

However, it is challenging to keep track of captions -especially if long- when they are placed inside the chunk options. Besides creating two separate chunks for each figure with captions inserted outside of the chunk, are there other options?


原文:https://stackoverflow.com/questions/35486935
更新时间:2023-02-22 14:02

最满意答案

亚历克斯,

我并不完全确定自己明白自己想要做什么,但是让我从我认为理解的地方对其进行刺探。

出于同样的理由(查看复杂性等),我经常在故事板中创建我的视图,然后从某个动作加载它们。 你可以做的是通过标识符来实例化视图控制器,如下所示:

FancyViewController *controller = [[self storyboard] 
              instantiateViewControllerWithIdentifier:@"FancyViewController"];

这假定你已经创建了一个叫做FancyViewController的UIViewController子类,并在storyboard中设置了你的视图控制器的类型。

现在,您可以将视图控制器显示在弹出窗口控制器中,或者将其推送到导航堆栈上。 你只需要确保你已经在故事板中为视图控制器设置了标识符。

在这里输入图像描述

此外,如果您使用popover控制器,并且每次触发操作时更新视图控制器属性,您都可能想要实例化视图控制器一次。 所以,如果它敲击触发弹出窗口的按钮,您的代码可能如下所示:

- (IBAction)didTapButtonToShowFancyViewController:(id)sender
{
  if (![self fancyViewController])
  {
    // fancyViewContrller is a property of type FancyViewController *
    fancyViewController = [[[self storyboard]
          instantiateViewControllerWithIdentifier:@"FancyViewController"];

    // fancyViewPopoverController is also a property
    fancyViewPopoverController = [[UIPopoverController alloc] 
                  initWithContentViewController:fancyViewController];
  }

  // Perform setup on the fancy controller you want to do every
  // time the action gets triggered here. Do initialization in the if
  // block above.

  // Now display the popover from the sender's frame. I'm assuming the
  // sender is a UIButton.
  [fancyViewPopoverController presentPopoverFromRect:[sender valueForKey:@"frame"] 
                              inView:[self view] 
              permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

动态设置弹出窗口的“锚点”的唯一方法是使用显式操作,该操作调用presentPopoverFromRect:permittedArrowDirections:animated:而不是segue。

我希望有所帮助。 如果我误解了你想要做的事,请告诉我。

最好的祝福。


Alex,

I'm not completely sure I understand what you're trying to do, but let me take a stab at it from what I think I understand.

For the same reason you cite (view complexity, etc.), I often build out my views in the storyboard and then load them from some action. What you can do is instantiate the view controller by identifier with something like this:

FancyViewController *controller = [[self storyboard] 
              instantiateViewControllerWithIdentifier:@"FancyViewController"];

This assumes you have created a UIViewController subclass called FancyViewController and have set the type for your view controller in the storyboard.

Now, you can display the view controller in a popover controller or you can push it onto a navigation stack. You just need to make sure you've set the identifier for your view controller in the storyboard.

enter image description here

Also, you'll probably want to instantiate your view controller once if you use a popover controller and just update the view controllers properties each time the action gets triggered. So, if it's tapping a button that triggers the popover, your code might look like this:

- (IBAction)didTapButtonToShowFancyViewController:(id)sender
{
  if (![self fancyViewController])
  {
    // fancyViewContrller is a property of type FancyViewController *
    fancyViewController = [[[self storyboard]
          instantiateViewControllerWithIdentifier:@"FancyViewController"];

    // fancyViewPopoverController is also a property
    fancyViewPopoverController = [[UIPopoverController alloc] 
                  initWithContentViewController:fancyViewController];
  }

  // Perform setup on the fancy controller you want to do every
  // time the action gets triggered here. Do initialization in the if
  // block above.

  // Now display the popover from the sender's frame. I'm assuming the
  // sender is a UIButton.
  [fancyViewPopoverController presentPopoverFromRect:[sender valueForKey:@"frame"] 
                              inView:[self view] 
              permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

The only way to set the popover's "anchor" dynamically is to use an explicit action that calls presentPopoverFromRect:permittedArrowDirections:animated: instead of a segue.

I hope that helps. Let me know if I've misunderstood what you're trying to do.

Best regards.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。